-
Notifications
You must be signed in to change notification settings - Fork 317
/
sft_data_process.py
51 lines (46 loc) · 1.23 KB
/
sft_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
51
import json
import numpy as np
from tqdm import tqdm
import pandas as pd
def sft_process():
with open('./sft_data/alpaca_gpt4_data_zh.json', 'r', encoding='utf-8') as f:
data = json.load(f)
#
q_lst = []
a_lst = []
for per in data:
q = per['instruction']
i = per['input']
a = per['output']
q = q + i
if len(q) < 10 or len(a) < 5:
continue
if len(q) > 256 or len(a) > 256:
continue
q_lst.append(q)
a_lst.append(a)
f = open('./sft_data/Belle_open_source_1M.json', 'r', encoding='utf-8')
# s
while True:
line = f.readline()
if not line:
break
per = json.loads(line)
q = per['instruction']
i = per['input']
a = per['output']
q = q + i
if len(q) < 10 or len(a) < 5:
continue
if len(q) > 256 or len(a) > 256:
continue
q_lst.append(q)
a_lst.append(a)
df = pd.DataFrame(columns=['prompt', 'answer'])
df['prompt'] = q_lst
df['answer'] = a_lst
df.to_csv('sft_data/sft_data.csv', index=False)
print(df)
save_dir = './sft_data'
if not os.path.exists(save_dir): os.makedirs(save_dir)
sft_process()