Download src/preprocess/AlphaNLI.py from OpenDFM/DialogZoo: direct link, hf CLI and curl.
- Browser
- Download file 2.53 kB
-
https://huggingface.co/datasets/OpenDFM/DialogZoo/resolve/main/src/preprocess/AlphaNLI.py
- Command line
-
hf download hf://datasets/OpenDFM/DialogZoo/src/preprocess/AlphaNLI.py
-
curl -L -o AlphaNLI.py https://huggingface.co/datasets/OpenDFM/DialogZoo/resolve/main/src/preprocess/AlphaNLI.py
2.53 kB
| 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["dialog"].append( | |
| # { | |
| # "roles": ["First hypothesis"], | |
| # "utterance": example["hyp1"], | |
| # } | |
| # ) | |
| # turn["dialog"].append( | |
| # { | |
| # "roles": ["Second hypothesis"], | |
| # "utterance": example["hyp2"], | |
| # "roles_to_select": [label2nl[labels[idx]] + " hypothesis"], | |
| # } | |
| # ) | |
| turn["knowledge"] = { | |
| "type": "text", | |
| "value": { | |
| "hypothesis candidate 1": example["hyp1"], | |
| "hypothesis candidate 2": example["hyp2"], | |
| }, | |
| } | |
| # turn["roles_to_select"] = ["HYPOTHESIS " + labels[idx]] | |
| turns.append(turn) | |
| # if labels[idx] == "1": | |
| # pos_hyp = example["hyp1"] | |
| # neg_hyp = example["hyp2"] | |
| # else: | |
| # pos_hyp = example["hyp2"] | |
| # neg_hyp = example["hyp1"] | |
| # # possitive hypothesis | |
| # pos_turn = copy.deepcopy(turn) | |
| # pos_turn["dialog"].append({"roles": ["HYPOTHESIS"], "utterance": pos_hyp, "class_label": True}) | |
| # # negative hypothesis | |
| # neg_turn = copy.deepcopy(turn) | |
| # neg_turn["dialog"].append({"roles": ["HYPOTHESIS"], "utterance": neg_hyp, "class_label": False}) | |
| # turns.append(pos_turn) | |
| # turns.append(neg_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) | |