|
from datasets import load_dataset |
|
import os |
|
import sys |
|
import json |
|
os.chdir(sys.path[0]) |
|
|
|
with open('CR_TEST.json', 'r') as f: |
|
jsonfile_test = json.load(f) |
|
|
|
|
|
def main(jsonfile, split): |
|
writefile = f"{split}.jsonl" |
|
with open(writefile, 'a') as f: |
|
for dict in jsonfile: |
|
if dict['label'] == 'negative': |
|
label = 0 |
|
elif dict['label'] == 'positive': |
|
label = 1 |
|
json_dict = {'text': dict['text'], |
|
'label': label, |
|
'label_text': dict['label']} |
|
|
|
f.write(json.dumps(json_dict)+'\n') |
|
|
|
if __name__ == "__main__": |
|
with open('CR_Test.json', 'r') as f: |
|
jsonfile_test = json.load(f) |
|
with open('CR_Train.json', 'r') as f: |
|
jsonfile_train = json.load(f) |
|
main(jsonfile=jsonfile_test, split='test') |
|
main(jsonfile=jsonfile_train, split='train') |
|
|
|
print("Job's done!") |