Datasets:

Modalities:
Text
Formats:
text
Libraries:
Datasets
License:
arubenruben commited on
Commit
ce4a429
1 Parent(s): 2e75448

Upload example_how_to_use_hf.py

Browse files
Files changed (1) hide show
  1. example_how_to_use_hf.py +40 -0
example_how_to_use_hf.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset, concatenate_datasets, Dataset, Features, Value, ClassLabel, DatasetDict
2
+ import dotenv
3
+ import os
4
+ import demoji
5
+ import re
6
+
7
+ dotenv.load_dotenv(dotenv.find_dotenv())
8
+ dataset = load_dataset('ruanchaves/hatebr')
9
+
10
+
11
+ dataset['train'] = concatenate_datasets(
12
+ [dataset['train'], dataset['validation']])
13
+
14
+ dataset = dataset.select_columns('instagram_comments')
15
+
16
+ dataset = dataset.rename_column('instagram_comments', 'text')
17
+
18
+ dataset_dict = DatasetDict({'train': None, 'test': None})
19
+
20
+ for split in ['train', 'test']:
21
+
22
+ df = dataset[split].to_pandas()
23
+
24
+ df['label'] = 'pt-BR'
25
+
26
+ for index, row in df.iterrows():
27
+ text = row['text'].strip()
28
+ text = text.replace('\n', ' ')
29
+ text = re.sub(r'\s+', ' ', text)
30
+ text = demoji.replace(text, '')
31
+
32
+ df.at[index, 'text'] = text
33
+
34
+ dataset_dict[split] = Dataset.from_pandas(df, split='train', features=Features({
35
+ "text": Value("string"),
36
+ "label": ClassLabel(num_classes=2, names=["pt-PT", "pt-BR"])
37
+ }))
38
+
39
+
40
+ dataset_dict.push_to_hub('hate_br_li', token=os.getenv("HF_TOKEN"))