| from utils import read_json_file, parse, write_jsonl_file |
| import os |
|
|
|
|
| def reformat(args, file): |
| path = os.path.join(args.input_dir, f"{file}.json") |
| data = read_json_file(path) |
|
|
| turns = [] |
| for turn in data: |
| t = {"turn": "multi", "locale": "en", "dialog": []} |
| for i, utt in enumerate(turn["History"][2:]): |
| d = {"roles": [("USER", "SYSTEM")[i % 2]], "utterance": utt} |
| t["dialog"].append(d) |
| d = { |
| "roles": ["USER"], |
| "utterance": turn["Question"], |
| "rewritten": turn["Rewrite"], |
| } |
| t["dialog"].append(d) |
|
|
| t["knowledge"] = { |
| "type": "dict", |
| "value": { |
| "article title": turn["History"][0], |
| "section title": turn["History"][1], |
| }, |
| } |
|
|
| turns.append(t) |
|
|
| write_jsonl_file(turns, os.path.join(args.output_dir, f"{file}.jsonl")) |
|
|
|
|
| def preprocess(args): |
| reformat(args, "train") |
| reformat(args, "dev") |
| reformat(args, "test") |
|
|
|
|
| if __name__ == "__main__": |
| args = parse() |
| preprocess(args) |
|
|