-
Notifications
You must be signed in to change notification settings - Fork 285
/
preprocess.py
46 lines (41 loc) · 1.22 KB
/
preprocess.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
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 = "The conversation between human and AI assistant.\n"
s = prompt + s + "[|Human|] "
data.append({"topic": topic, "input": s})
json.dump(data, open("data/{}_chat_data.json".format(data_name), "w"))