Karroyan commited on
Commit
46f2aa9
·
verified ·
1 Parent(s): 9101f13

Upload integrate_data.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. integrate_data.py +44 -0
integrate_data.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ train_path = ['/fs-computility/niuyazhe/lixueyan/meme/dataset-meme-rewardmodel/boringmeme_align_multihead',
2
+ '/fs-computility/niuyazhe/lixueyan/meme/dataset-meme-rewardmodel/boringmeme_cross_multihead',
3
+ '/fs-computility/niuyazhe/lixueyan/meme/dataset-meme-rewardmodel/irrelevantmeme_align_multihead',
4
+ '/fs-computility/niuyazhe/lixueyan/meme/dataset-meme-rewardmodel/irrelevantmeme_cross_multihead',
5
+ '/fs-computility/niuyazhe/lixueyan/meme/dataset-meme-rewardmodel/lowperformancememe_align_multihead',
6
+ '/fs-computility/niuyazhe/lixueyan/meme/dataset-meme-rewardmodel/lowperformancememe_cross_multihead',
7
+ '/fs-computility/niuyazhe/lixueyan/meme/dataset-meme-rewardmodel/text_replaced_align_multihead',
8
+ '/fs-computility/niuyazhe/lixueyan/meme/dataset-meme-rewardmodel/text_replaced_cross_multihead',
9
+ ]
10
+
11
+ # open all the train_path, find the jsonl file end with train.jsonl, and put the dataset name into a jsonl called allmeme_multihead
12
+
13
+ import os
14
+ import json
15
+
16
+ train_data_path = {}
17
+ test_data_path = {}
18
+
19
+ for path in train_path:
20
+ for file in os.listdir(path):
21
+ if file.endswith('train.jsonl'):
22
+ # read the jsonl
23
+ with open(os.path.join(path, file), 'r') as f:
24
+ for line in f:
25
+ data = json.loads(line)
26
+ key = list(data.keys())[0]
27
+ train_data_path[key] = data[key]
28
+
29
+ if file.endswith('test.jsonl'):
30
+ # read the jsonl
31
+ with open(os.path.join(path, file), 'r') as f:
32
+ for line in f:
33
+ data = json.loads(line)
34
+ key = list(data.keys())[0]
35
+ test_data_path[key] = data[key]
36
+
37
+
38
+ # write the train_data_path into a jsonl file
39
+ with open('allmeme_multihead/allmeme_multihead_train.jsonl', 'w') as f:
40
+ f.write(json.dumps(train_data_path) + '\n')
41
+
42
+ # write the test_data_path into a jsonl file
43
+ with open('allmeme_multihead/allmeme_multihead_test.jsonl', 'w') as f:
44
+ f.write(json.dumps(test_data_path) + '\n')