-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_process.py
50 lines (44 loc) · 1.56 KB
/
data_process.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import json
# json, k,v
def process_kv(path_to_data,save_name):
new_data = []
with open(path_to_data, 'r') as f:
data = json.load(f)
for _, val in data.items():
new_data.append({
'text':(
"instruction:{ins}\n"
"output:{out}"
).format(ins=val['prompt_question'],
out=val['prompt_answer']),
'final_decision': val['final_decision']
})
f.close()
with open(save_name, 'w', encoding='utf-8') as f:
print(json.dumps(new_data, ensure_ascii=False, indent=4), file=f)
f.close()
# with open(save_name, 'w', encoding='utf-8') as f:
# for line in new_data:
# print(json.dumps(line, ensure_ascii=False, indent=4), file=f)
# f.close()
# josn, list
def process_list(path_to_data,save_name):
new_data = []
with open(path_to_data, 'r') as f:
data = json.load(f)
for i in data:
new_data.append({
'text': (
"instruction:{ins}\n"
"output:{out}"
).format(ins=i['prompt_question'],
out=i['prompt_answer']),
'final_decision': i['final_decision']
})
f.close()
with open(save_name, 'w', encoding='utf-8') as f:
for line in new_data:
print(json.dumps(line, ensure_ascii=False, indent=4))
f.close()
if __name__ == '__main__':
process_kv("pqal_pmt.json","processed_data/pqal_pmt_process.json")