| | from utils import read_jsonl_file, write_jsonl_file, parse, read_line_labels |
| | import os |
| | import copy |
| |
|
| | label2nl = {"1": "First", "2": "Second"} |
| |
|
| |
|
| | def preprocess_for_train_and_dev(args, file): |
| | data_path = os.path.join(args.input_dir, f"{file}.jsonl") |
| | data = read_jsonl_file(data_path) |
| |
|
| | label_path = os.path.join(args.input_dir, f"{file}-labels.lst") |
| | labels = read_line_labels(label_path) |
| |
|
| | turns = [] |
| | for idx, example in enumerate(data): |
| | turn = { |
| | "turn": "multi", |
| | "locale": "en", |
| | "dialog": [ |
| | {"roles": ["First observation"], "utterance": example["obs1"]}, |
| | { |
| | "roles": ["Second observation"], |
| | "utterance": example["obs2"], |
| | "roles_to_select": [f"hypothesis candidate {labels[idx]}"], |
| | }, |
| | ], |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | turn["knowledge"] = { |
| | "type": "text", |
| | "value": { |
| | "hypothesis candidate 1": example["hyp1"], |
| | "hypothesis candidate 2": example["hyp2"], |
| | }, |
| | } |
| |
|
| | |
| | turns.append(turn) |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| |
|
| | |
| | |
| |
|
| | write_jsonl_file(turns, os.path.join(args.output_dir, f"{file}.jsonl")) |
| |
|
| |
|
| | def preprocess(args): |
| | preprocess_for_train_and_dev(args, "train") |
| | preprocess_for_train_and_dev(args, "dev") |
| |
|
| |
|
| | if __name__ == "__main__": |
| | args = parse() |
| | preprocess(args) |
| |
|