DialogZoo / src /preprocess /CommonsenseDialog.py
AnAutomaticPencil's picture
data preprocessing update
a6326c7
raw
history blame contribute delete
956 Bytes
import re
from utils import (
read_json_file,
read_jsonl_file,
write_json_file,
write_jsonl_file,
parse,
)
def reformat(args, file):
path = args.input_dir + "/" + file + ".json"
data = read_json_file(path)
turns = []
for turn_ in data:
turn = data[turn_]
speaker = turn["speaker"]
t = {"turn": "multi", "locale": "en", "dialog": []}
for j, tt in enumerate(turn["turns"]):
d = {"roles": [str([speaker, "third-person"][j % 2])], "utterance": tt}
t["dialog"].append(d)
t["knowledge"] = {"type": "str", "value": {"context": turn["context"]}}
turns.append(t)
if file == "valid":
file = "dev"
write_jsonl_file(turns, args.output_dir + "/" + file + ".jsonl")
def preprocess(args):
reformat(args, "train")
reformat(args, "valid")
reformat(args, "test")
if __name__ == "__main__":
args = parse()
preprocess(args)