nouamanetazi HF staff commited on
Commit
d604517
1 Parent(s): 185858e

Create create_data.py

Browse files
Files changed (1) hide show
  1. create_data.py +30 -0
create_data.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import DatasetDict, load_dataset
2
+ import csv
3
+ import json
4
+
5
+ def main():
6
+ label2id = {"positive": 2, "neutral": 1, "negative": 0}
7
+
8
+ for split in ["train", "test"]:
9
+ input_file = csv.DictReader(open(f"raw_data/{split}_csv"))
10
+
11
+ with open(f'{split}.jsonl', 'w') as fOut:
12
+ for row in input_file:
13
+ fOut.write(json.dumps({'id': row['textID'], 'text': row['text'], 'label': label2id[row['sentiment']], 'label_text': row['sentiment']})+"\n")
14
+
15
+
16
+ """
17
+ train_dset = load_dataset("csv", data_files="raw_data/train_csv", split="train")
18
+ train_dset = train_dset.remove_columns(["selected_text"])
19
+ test_dset = load_dataset("csv", data_files="raw_data/train_csv", split="train")
20
+ raw_dset = DatasetDict()
21
+ raw_dset["train"] = train_dset
22
+ raw_dset["test"] = test_dset
23
+ for split, dset in raw_dset.items():
24
+ dset = dset.rename_column("sentiment", "label_text")
25
+ dset = dset.map(lambda x: {"label": label2id[x["label_text"]]}, num_proc=8)
26
+ dset.to_json(f"{split}.jsonl")
27
+ """
28
+
29
+ if __name__ == "__main__":
30
+ main()