forked from project-baize/baize-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocess.py
More file actions
47 lines (42 loc) · 1.27 KB
/
preprocess.py
File metadata and controls
47 lines (42 loc) · 1.27 KB
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
import pickle
import json
import sys
import os
data_name = str(sys.argv[1])
if not os.path.exists("data"):
os.makedirs("data")
data = []
for i in range(100):
try:
temp = pickle.load(
open("collected_data/{}_chat_{}.pkl".format(data_name, i), "rb")
)
except:
continue
for topic in temp:
x = temp[topic]
x = x.split("[Human]")[1:-1]
if len(x) != 0:
s = ""
for y in x:
if "[AI]" in y:
y = y.split("[AI]")
if len(y) == 2:
s += (
"[|Human|] "
+ y[0].strip()
+ "\n"
+ "[|AI|] "
+ y[1].strip()
+ "\n"
)
else:
break
else:
break
if s != "":
prompt = "인간과 AI 어시스턴트 간의 대화입니다.\n"
s = prompt + s + "[|Human|] "
data.append({"topic": topic, "input": s})
print('data', len(data))
json.dump(data, open("data/{}_chat_data.json".format(data_name), "w"), ensure_ascii=False)