DialogZoo / src /preprocess /MInDS-14.py
AnAutomaticPencil's picture
data preprocessing update
a6326c7
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)