| | 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}_rand_split.jsonl") |
| | 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": {"question concept": example["question"]["question_concept"]}, |
| | }, |
| | } |
| |
|
| | dial["dialog"].append( |
| | {"roles": ["USER"], "utterance": example["question"]["stem"], "roles_to_select": [example["answerKey"]]} |
| | ) |
| |
|
| | for choice in example["question"]["choices"]: |
| | dial["knowledge"]["value"][choice["label"]] = choice["text"] |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| |
|
| | |
| | |
| |
|
| | processed_data.append(dial) |
| |
|
| | write_jsonl_file(processed_data, outfile) |
| |
|
| |
|
| | if __name__ == "__main__": |
| | args = parse() |
| | preprocess(args, "train") |
| | preprocess(args, "dev") |
| |
|