Download src/preprocess/DDRel.py from OpenDFM/DialogZoo: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/datasets/OpenDFM/DialogZoo/resolve/main/src/preprocess/DDRel.py
- Command line
-
hf download hf://datasets/OpenDFM/DialogZoo/src/preprocess/DDRel.py
-
curl -L -o DDRel.py https://huggingface.co/datasets/OpenDFM/DialogZoo/resolve/main/src/preprocess/DDRel.py
1.41 kB
| from utils import ( | |
| read_jsonl_file, | |
| write_jsonl_file, | |
| parse, | |
| ) | |
| label2relation = { | |
| "1": "Child and Parent", | |
| "2": "Child and Other Family Elder", | |
| "3": "Siblings", | |
| "4": "Spouse", | |
| "5": "Lovers", | |
| "6": "Courtship", | |
| "7": "Friends", | |
| "8": "Neighbors", | |
| "9": "Roommates", | |
| "10": "Workplace Superior and Subordinate", | |
| "11": "Colleague or Partners", | |
| "12": "Opponents", | |
| "13": "Professional Contact", | |
| } | |
| def reformat(args, file): | |
| path = args.input_dir + "/" + file + ".txt" | |
| data = read_jsonl_file(path) | |
| turns = [] | |
| for i in range(len(data)): | |
| t = {"turn": "multi", "locale": "en", "dialog": []} | |
| AB2name = {"A": data[i]["nameA"], "B": data[i]["nameB"]} | |
| for c in data[i]["context"]: | |
| role = c[0] | |
| utterance = c[2:].strip() | |
| # one bad case | |
| if role not in AB2name: | |
| role = "B" | |
| utterance = c | |
| d = {"roles": [AB2name[role]], "utterance": utterance} | |
| t["dialog"].append(d) | |
| t["role_relations"] = [{"relation": label2relation[data[i]["label"]]}] | |
| turns.append(t) | |
| write_jsonl_file(turns, args.output_dir + "/" + file + ".jsonl") | |
| def preprocess(args): | |
| reformat(args, "train") | |
| reformat(args, "dev") | |
| reformat(args, "test") | |
| if __name__ == "__main__": | |
| args = parse() | |
| preprocess(args) | |