Download src/preprocess/MInDS-14.py from OpenDFM/DialogZoo: direct link, hf CLI and curl.
- Browser
- Download file 1.64 kB
-
https://huggingface.co/datasets/OpenDFM/DialogZoo/resolve/main/src/preprocess/MInDS-14.py
- Command line
-
hf download hf://datasets/OpenDFM/DialogZoo/src/preprocess/MInDS-14.py
-
curl -L -o MInDS-14.py https://huggingface.co/datasets/OpenDFM/DialogZoo/resolve/main/src/preprocess/MInDS-14.py
1.64 kB
| import os | |
| # import pandas as pd | |
| from utils import read_csv_file, write_jsonl_file, parse | |
| # new read_in function | |
| # def read_csv_file(filename): | |
| # with open(filename, "r", encoding="utf8") as fr: | |
| # return pd.read_csv(fr) | |
| def preprocess(args): | |
| filenames = os.listdir(args.input_dir) | |
| for filename in filenames: | |
| """ | |
| add train/eval/test instruction | |
| """ | |
| if not filename.endswith(".csv"): | |
| continue | |
| path = os.path.join(args.input_dir, filename) | |
| data = read_csv_file(path) | |
| turns = [] | |
| locale = filename[:5] if filename != "aux-en.csv" else "en-US" | |
| for i in data.index: | |
| t = {"turn": "single", "locale": locale, "dialog": []} | |
| item = data.iloc[i] | |
| d = { | |
| "role": "ROLE", | |
| "utterance": item["text_asr"] if filename != "aux-en.csv" else item[0], | |
| "active_intents": [ | |
| item["intent"] if filename != "aux-en.csv" else item[1] | |
| ], | |
| } | |
| t["dialog"].append(d) | |
| turns.append(t) | |
| if locale != "en-US": | |
| t_en = {"turn": "single", "locale": "en-US", "dialog": []} | |
| d = { | |
| "role": "ROLE", | |
| "utterance": item["text_translated"], | |
| "active_intents": [item["intent"]], | |
| } | |
| t_en["dialog"].append(d) | |
| turns.append(t_en) | |
| write_jsonl_file(turns, args.output_dir + "/" + filename[:5] + ".jsonl") | |
| if __name__ == "__main__": | |
| args = parse() | |
| preprocess(args) | |