forked from zhaoxlpku/KnowledGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.py
31 lines (26 loc) · 1.05 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
import argparse
import os
import json
from wizard_generator import data_generator
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Pre-training for Knowledge-Grounded Conversation'
)
parser.add_argument('--in_file', type=str, default='')
parser.add_argument('--out_file', type=str, default='')
args = parser.parse_args()
# in_file = "/home/zhaoxl/Data/wizard_of_wikipedia/test_random_split.json"
# out_file = "/home/zhaoxl/KnowledGPT/data/wizard_of_wikipedia/test_seen.jsonl"
out_dir = os.path.dirname(args.out_file)
if not os.path.exists(out_dir):
os.makedirs(out_dir)
with open(args.out_file, 'w', encoding='utf-8') as f:
for history, user, response, knowledge in data_generator(args.in_file, correct_first=True, keep_last_n=2):
f.write(
json.dumps({
'history': history,
'user': user,
'response': response,
'knowledge': knowledge
}) + '\n'
)