|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""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("string"),)), |
|
"task description": datasets.Sequence(datasets.Value("string")), |
|
"type": datasets.Value("string"), |
|
"messages": datasets.Sequence( |
|
{ |
|
"content": datasets.Value("string"), |
|
"role": datasets.Value("string"), |
|
"dialog_act": datasets.Sequence((datasets.Value("string"),)), |
|
"user_state": datasets.Sequence((datasets.Value("string"),)), |
|
"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((datasets.Value("string"),)), |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
|
|
return [ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
datasets.SplitGenerator( |
|
name="challenge.butterfingers", |
|
|
|
gen_kwargs={ |
|
"filepath": dl_manager.download_and_extract("challenge_butterfingers.jsonl"), |
|
"split": "challenge", |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples( |
|
self, filepath, split |
|
): |
|
""" Yields examples as (key, example) tuples. """ |
|
|
|
|
|
def empty_sys_state(): |
|
return { |
|
"景点": { |
|
"名称": "", |
|
"门票": "", |
|
"游玩时间": "", |
|
"评分": "", |
|
"周边景点": "", |
|
"周边餐馆": "", |
|
"周边酒店": "", |
|
"selectedResults": [] |
|
}, |
|
"餐馆": { |
|
"名称": "", |
|
"推荐菜": "", |
|
"人均消费": "", |
|
"评分": "", |
|
"周边景点": "", |
|
"周边餐馆": "", |
|
"周边酒店": "", |
|
"selectedResults": [] |
|
}, |
|
"酒店": { |
|
"名称": "", |
|
"酒店类型": "", |
|
"酒店设施": "", |
|
"价格": "", |
|
"评分": "", |
|
"周边景点": "", |
|
"周边餐馆": "", |
|
"周边酒店": "", |
|
"selectedResults": [] |
|
}, |
|
"地铁": { |
|
"出发地": "", |
|
"目的地": "", |
|
"selectedResults": [] |
|
}, |
|
"出租": { |
|
"出发地": "", |
|
"目的地": "", |
|
"selectedResults": [] |
|
} |
|
} |
|
|
|
if split == 'challenge': |
|
with open(filepath, encoding="utf-8") as f: |
|
for id_, row in enumerate(f): |
|
data = json.loads(row) |
|
yield id_, { |
|
"sentence": data["sentence"], |
|
"label": data["label"], |
|
"gem_id": data["gem_id"] |
|
} |
|
|
|
key = 0 |
|
with open(filepath, encoding="utf-8") as f: |
|
data = json.load(f) |
|
for dialog_id, dialog in data.items(): |
|
if split == "challenge.CM+T" and dialog["type"] != "不独立多领域+交通": |
|
continue |
|
messages = [] |
|
for turn in dialog["messages"]: |
|
if "user_state" not in turn: |
|
turn["user_state"] = [] |
|
else: |
|
turn["user_state"] = list(map(tuple, 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"GEM-CrossWOZ-{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": list(map(tuple, dialog["final_goal"])) |
|
} |
|
key += 1 |
|
|