Commit
·
756ad8d
1
Parent(s):
a77ec81
Upload create_dataset.py
Browse files- create_dataset.py +33 -0
create_dataset.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datasets import load_dataset
|
2 |
+
import os
|
3 |
+
import sys
|
4 |
+
import json
|
5 |
+
os.chdir(sys.path[0])
|
6 |
+
|
7 |
+
with open('CR_TEST.json', 'r') as f:
|
8 |
+
jsonfile_test = json.load(f)
|
9 |
+
|
10 |
+
|
11 |
+
def main(jsonfile, split):
|
12 |
+
writefile = f"{split}.jsonl"
|
13 |
+
with open(writefile, 'a') as f:
|
14 |
+
for dict in jsonfile:
|
15 |
+
if dict['label'] == 'negative':
|
16 |
+
label = 0
|
17 |
+
elif dict['label'] == 'positive':
|
18 |
+
label = 1
|
19 |
+
json_dict = {'text': dict['text'],
|
20 |
+
'label': label,
|
21 |
+
'label_text': dict['label']}
|
22 |
+
|
23 |
+
f.write(json.dumps(json_dict)+'\n')
|
24 |
+
|
25 |
+
if __name__ == "__main__":
|
26 |
+
with open('CR_Test.json', 'r') as f:
|
27 |
+
jsonfile_test = json.load(f)
|
28 |
+
with open('CR_Train.json', 'r') as f:
|
29 |
+
jsonfile_train = json.load(f)
|
30 |
+
main(jsonfile=jsonfile_test, split='test')
|
31 |
+
main(jsonfile=jsonfile_train, split='train')
|
32 |
+
|
33 |
+
print("Job's done!")
|