| import os |
| from utils import read_jsonl_file, write_jsonl_file, parse, choices |
|
|
|
|
| def preprocess(args, split): |
| infile = os.path.join(args.input_dir, f"{split}.jsonl") |
|
|
| if split == "valid": |
| split = "dev" |
| outfile = os.path.join(args.output_dir, f"{split}.jsonl") |
|
|
| data = read_jsonl_file(infile) |
| processed_data = [] |
|
|
| for example in data: |
| dial = { |
| "turn": "single", |
| "locale": "en", |
| "dialog": [], |
| "knowledge": {"type": "dict", "value": {}}, |
| } |
|
|
| dial["dialog"].append({"roles": ["USER"], "utterance": example["question"]}) |
|
|
| example.pop("question") |
| example.pop("id") |
|
|
| label = example.pop("label") |
|
|
| |
|
|
| assert len(list(example.keys())) == 5 |
| for i in range(4): |
| answer = example[f"answer{i}"] |
| |
| |
| |
| dial["knowledge"]["value"][f"answer{i}"] = answer |
|
|
| dial["dialog"][-1]["roles_to_select"] = [f"answer{label}"] |
|
|
| dial["knowledge"]["value"]["passage"] = example["context"] |
| processed_data.append(dial) |
|
|
| write_jsonl_file(processed_data, outfile) |
|
|
|
|
| if __name__ == "__main__": |
| args = parse() |
| preprocess(args, "train") |
| preprocess(args, "valid") |
|
|