| import os | |
| from utils import read_jsonl_file, write_jsonl_file, parse | |
| ''' | |
| This is script is used to process the whole file of MKQA | |
| Every two sentences (QA objects) in a line share the same language | |
| ''' | |
| def preprocess(args): | |
| path = os.path.join(args.input_dir, "mkqa.jsonl") | |
| data = read_jsonl_file(path) | |
| ''' | |
| add add train/eval/test instruction and language chosen | |
| ''' | |
| locales = list(data[0]["answers"].keys()) | |
| pack = [] | |
| for line in data: | |
| for locale in locales: | |
| t = { | |
| "turn": "multi", | |
| "locale": locale, | |
| "dialog": [] | |
| } | |
| que = { | |
| "role": "question", | |
| "utterance": line["queries"][locale] | |
| } | |
| ans = { | |
| "role": "answer", | |
| "utterance": line["answers"][locale][0]["text"] | |
| } | |
| t["dialog"].append(que) | |
| t["dialog"].append(ans) | |
| pack.append(t) | |
| write_jsonl_file(pack, os.path.join(args.output_dir, "mkqa_preprocessed.jsonl")) | |
| if __name__ == "__main__": | |
| args = parse() | |
| preprocess(args) |