|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""CrossWOZ: A Large-Scale Chinese Cross-Domain Task-Oriented Dialogue Dataset""" |
|
|
|
|
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@article{zhu2020crosswoz, |
|
author = {Qi Zhu and Kaili Huang and Zheng Zhang and Xiaoyan Zhu and Minlie Huang}, |
|
title = {Cross{WOZ}: A Large-Scale Chinese Cross-Domain Task-Oriented Dialogue Dataset}, |
|
journal = {Transactions of the Association for Computational Linguistics}, |
|
year = {2020} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
CrossWOZ is the first large-scale Chinese Cross-Domain Wizard-of-Oz task-oriented dataset. \ |
|
It contains 6K dialogue sessions and 102K utterances for 5 domains, including hotel, \ |
|
restaurant, attraction, metro, and taxi. Moreover, the corpus contains rich annotation of \ |
|
dialogue states and dialogue acts at both user and system sides. |
|
""" |
|
|
|
_HOMEPAGE = "https://github.com/thu-coai/CrossWOZ" |
|
|
|
_LICENSE = "Apache License, Version 2.0" |
|
|
|
|
|
class CrossWOZ(datasets.GeneratorBasedBuilder): |
|
"""CrossWOZ: A Large-Scale Chinese Cross-Domain Task-Oriented Dialogue Dataset""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"gem_id": datasets.Value("string"), |
|
"dialog_id": datasets.Value("string"), |
|
"sys_id": datasets.Value("int32"), |
|
"usr_id": datasets.Value("int32"), |
|
"goal": datasets.Sequence((datasets.Value("int32"),datasets.Value("string"),datasets.Value("string"),datasets.Value("string"),datasets.Value("bool"))), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"task description": datasets.Value("string"), |
|
"type": datasets.Value("string"), |
|
"messages": datasets.Sequence( |
|
{ |
|
"content": datasets.Value("string"), |
|
"role": datasets.Value("string"), |
|
"dialog_act": datasets.Sequence( |
|
{ |
|
"intent": datasets.Value("string"), |
|
"domain": datasets.Value("string"), |
|
"slot": datasets.Value("string"), |
|
"value": datasets.Value("string"), |
|
} |
|
), |
|
"user_state": datasets.Sequence( |
|
{ |
|
"sub_goal_id": datasets.Value("int32"), |
|
"domain": datasets.Value("string"), |
|
"slot": datasets.Value("string"), |
|
"value": datasets.Value("string"), |
|
"has_mentioned": datasets.Value("bool"), |
|
} |
|
), |
|
"sys_state": { |
|
"景点": { |
|
"名称": datasets.Value("string"), |
|
"门票": datasets.Value("string"), |
|
"游玩时间": datasets.Value("string"), |
|
"评分": datasets.Value("string"), |
|
"周边景点": datasets.Value("string"), |
|
"周边餐馆": datasets.Value("string"), |
|
"周边酒店": datasets.Value("string"), |
|
"selectedResults": datasets.Sequence(datasets.Value("string")) |
|
}, |
|
"餐馆": { |
|
"名称": datasets.Value("string"), |
|
"推荐菜": datasets.Value("string"), |
|
"人均消费": datasets.Value("string"), |
|
"评分": datasets.Value("string"), |
|
"周边景点": datasets.Value("string"), |
|
"周边餐馆": datasets.Value("string"), |
|
"周边酒店": datasets.Value("string"), |
|
"selectedResults": datasets.Sequence(datasets.Value("string")) |
|
}, |
|
"酒店": { |
|
"名称": datasets.Value("string"), |
|
"酒店类型": datasets.Value("string"), |
|
"酒店设施": datasets.Value("string"), |
|
"价格": datasets.Value("string"), |
|
"评分": datasets.Value("string"), |
|
"周边景点": datasets.Value("string"), |
|
"周边餐馆": datasets.Value("string"), |
|
"周边酒店": datasets.Value("string"), |
|
"selectedResults": datasets.Sequence(datasets.Value("string")) |
|
}, |
|
"地铁": { |
|
"出发地": datasets.Value("string"), |
|
"目的地": datasets.Value("string"), |
|
"selectedResults": datasets.Sequence(datasets.Value("string")) |
|
}, |
|
"出租": { |
|
"出发地": datasets.Value("string"), |
|
"目的地": datasets.Value("string"), |
|
"selectedResults": datasets.Sequence(datasets.Value("string")) |
|
} |
|
}, |
|
"sys_state_init": { |
|
"景点": { |
|
"名称": datasets.Value("string"), |
|
"门票": datasets.Value("string"), |
|
"游玩时间": datasets.Value("string"), |
|
"评分": datasets.Value("string"), |
|
"周边景点": datasets.Value("string"), |
|
"周边餐馆": datasets.Value("string"), |
|
"周边酒店": datasets.Value("string"), |
|
"selectedResults": datasets.Sequence(datasets.Value("string")) |
|
}, |
|
"餐馆": { |
|
"名称": datasets.Value("string"), |
|
"推荐菜": datasets.Value("string"), |
|
"人均消费": datasets.Value("string"), |
|
"评分": datasets.Value("string"), |
|
"周边景点": datasets.Value("string"), |
|
"周边餐馆": datasets.Value("string"), |
|
"周边酒店": datasets.Value("string"), |
|
"selectedResults": datasets.Sequence(datasets.Value("string")) |
|
}, |
|
"酒店": { |
|
"名称": datasets.Value("string"), |
|
"酒店类型": datasets.Value("string"), |
|
"酒店设施": datasets.Value("string"), |
|
"价格": datasets.Value("string"), |
|
"评分": datasets.Value("string"), |
|
"周边景点": datasets.Value("string"), |
|
"周边餐馆": datasets.Value("string"), |
|
"周边酒店": datasets.Value("string"), |
|
"selectedResults": datasets.Sequence(datasets.Value("string")) |
|
}, |
|
"地铁": { |
|
"出发地": datasets.Value("string"), |
|
"目的地": datasets.Value("string"), |
|
"selectedResults": datasets.Sequence(datasets.Value("string")) |
|
}, |
|
"出租": { |
|
"出发地": datasets.Value("string"), |
|
"目的地": datasets.Value("string"), |
|
"selectedResults": datasets.Sequence(datasets.Value("string")) |
|
} |
|
}, |
|
} |
|
), |
|
"final_goal": datasets.Sequence( |
|
{ |
|
"sub_goal_id": datasets.Value("int32"), |
|
"domain": datasets.Value("string"), |
|
"slot": datasets.Value("string"), |
|
"value": datasets.Value("string"), |
|
"has_mentioned": datasets.Value("bool"), |
|
} |
|
) |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
data_dir = dl_manager.download_and_extract("data.zip") |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "train.json"), |
|
"split": "train", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "test.json"), |
|
"split": "test" |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "val.json"), |
|
"split": "dev", |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples( |
|
self, filepath, split |
|
): |
|
""" Yields examples as (key, example) tuples. """ |
|
|
|
|
|
def convert_goal(raw_goal): |
|
goal = [] |
|
for subgoal in raw_goal: |
|
goal.append({ |
|
"sub_goal_id": subgoal[0], |
|
"domain": subgoal[1], |
|
"slot": subgoal[2], |
|
"value": str(subgoal[3]), |
|
"has_mentioned": subgoal[4], |
|
}) |
|
return goal |
|
|
|
def empty_sys_state(): |
|
return { |
|
"景点": { |
|
"名称": "", |
|
"门票": "", |
|
"游玩时间": "", |
|
"评分": "", |
|
"周边景点": "", |
|
"周边餐馆": "", |
|
"周边酒店": "", |
|
"selectedResults": [] |
|
}, |
|
"餐馆": { |
|
"名称": "", |
|
"推荐菜": "", |
|
"人均消费": "", |
|
"评分": "", |
|
"周边景点": "", |
|
"周边餐馆": "", |
|
"周边酒店": "", |
|
"selectedResults": [] |
|
}, |
|
"酒店": { |
|
"名称": "", |
|
"酒店类型": "", |
|
"酒店设施": "", |
|
"价格": "", |
|
"评分": "", |
|
"周边景点": "", |
|
"周边餐馆": "", |
|
"周边酒店": "", |
|
"selectedResults": [] |
|
}, |
|
"地铁": { |
|
"出发地": "", |
|
"目的地": "", |
|
"selectedResults": [] |
|
}, |
|
"出租": { |
|
"出发地": "", |
|
"目的地": "", |
|
"selectedResults": [] |
|
} |
|
} |
|
|
|
key = 0 |
|
with open(filepath, encoding="utf-8") as f: |
|
data = json.load(f) |
|
for dialog_id, dialog in data.items(): |
|
messages = [] |
|
for turn in dialog["messages"]: |
|
dialog_act = [] |
|
for da in turn["dialog_act"]: |
|
dialog_act.append({ |
|
"intent": da[0], |
|
"domain": da[1], |
|
"slot": da[2], |
|
"value": da[3], |
|
}) |
|
turn["dialog_act"] = dialog_act |
|
if "user_state" not in turn: |
|
turn["user_state"] = [] |
|
else: |
|
turn["user_state"] = convert_goal(turn["user_state"]) |
|
if "sys_state" not in turn: |
|
turn["sys_state"] = empty_sys_state() |
|
if "sys_state_init" not in turn: |
|
turn["sys_state_init"] = empty_sys_state() |
|
messages.append(turn) |
|
|
|
yield key, { |
|
"gem_id": f"{self.config.name}-{split}-{key}", |
|
"dialog_id": dialog_id, |
|
"sys_id": dialog["sys-usr"][0], |
|
"usr_id": dialog["sys-usr"][1], |
|
"goal": list(map(tuple, dialog["goal"])), |
|
"task description": dialog["task description"], |
|
"type": dialog["type"], |
|
"messages": messages, |
|
"final_goal": convert_goal(dialog["final_goal"]) |
|
} |
|
key += 1 |
|
|