File size: 897 Bytes
756ad8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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!")