|
import re |
|
from utils import ( |
|
read_json_file, |
|
read_jsonl_file, |
|
write_json_file, |
|
write_jsonl_file, |
|
parse, |
|
) |
|
|
|
|
|
def preprocess_for_train_and_dev(args, file): |
|
path = args.input_dir + "/" + file |
|
data = read_jsonl_file(path) |
|
|
|
turns = [] |
|
for i in range(len(data)): |
|
t = { |
|
"turn": "multi", |
|
"domain": [data[i]["topic"]], |
|
"locale": "en", |
|
"dialog": [], |
|
"summary": "", |
|
} |
|
dialogues = re.split("\\n|\\r\\n", data[i]["dialogue"]) |
|
for dialog in dialogues: |
|
ro = re.search("(#.+#): ", dialog) |
|
ru = re.split("#:", dialog) |
|
|
|
if ro.group(1) is None: |
|
print(dialog) |
|
exit() |
|
d = {"roles": [ro.group(1)], "utterance": ru[1].strip()} |
|
t["dialog"].append(d) |
|
t["summary"] = data[i]["summary"] |
|
|
|
turns.append(t) |
|
|
|
write_jsonl_file(turns, args.output_dir + "/" + file) |
|
|
|
|
|
def preprocess_for_test(args, file): |
|
path = args.input_dir + "/" + file |
|
data = read_jsonl_file(path) |
|
|
|
turns = [] |
|
for i in range(len(data)): |
|
t = { |
|
"turn": "multi", |
|
"domain": [data[i]["topic1"], data[i]["topic2"], data[i]["topic3"]], |
|
"locale": "en", |
|
"dialog": [], |
|
"summary": "", |
|
} |
|
dialogues = re.split("\\n|\\r\\n", data[i]["dialogue"]) |
|
for dialog in dialogues: |
|
ro = re.search("(#.+#):", dialog) |
|
ru = re.split("#:", dialog) |
|
|
|
if ro is None: |
|
print(dialog) |
|
exit() |
|
d = {"roles": [ro.group(1)], "utterance": ru[1].strip()} |
|
t["dialog"].append(d) |
|
t["summary"] = "__multi_ref_sep__".join( |
|
[data[i]["summary1"], data[i]["summary2"], data[i]["summary3"]] |
|
) |
|
|
|
turns.append(t) |
|
|
|
write_jsonl_file(turns, args.output_dir + "/" + file) |
|
|
|
|
|
def preprocess(args): |
|
preprocess_for_train_and_dev(args, "dialogsum.train.jsonl") |
|
preprocess_for_train_and_dev(args, "dialogsum.dev.jsonl") |
|
preprocess_for_test(args, "dialogsum.test.jsonl") |
|
|
|
|
|
if __name__ == "__main__": |
|
args = parse() |
|
preprocess(args) |
|
|