Datasets:
File size: 13,106 Bytes
5bdb646 295337c 5bdb646 7c726ab 5bdb646 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""MultiWOZ v2.2: Multi-domain Wizard of OZ version 2.2"""
import json
import datasets
# TODO: Add BibTeX citation
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\
@article{corr/abs-2007-12720,
author = {Xiaoxue Zang and
Abhinav Rastogi and
Srinivas Sunkara and
Raghav Gupta and
Jianguo Zhang and
Jindong Chen},
title = {MultiWOZ 2.2 : {A} Dialogue Dataset with Additional Annotation Corrections
and State Tracking Baselines},
journal = {CoRR},
volume = {abs/2007.12720},
year = {2020},
url = {https://arxiv.org/abs/2007.12720},
archivePrefix = {arXiv},
eprint = {2007.12720}
}
"""
# TODO: Add description of the dataset here
# You can copy an official description
_DESCRIPTION = """\
Multi-Domain Wizard-of-Oz dataset (MultiWOZ), a fully-labeled collection of human-human written conversations spanning over multiple domains and topics.
MultiWOZ 2.1 (Eric et al., 2019) identified and fixed many erroneous annotations and user utterances in the original version, resulting in an
improved version of the dataset. MultiWOZ 2.2 is a yet another improved version of this dataset, which identifies and fizes dialogue state annotation errors
across 17.3% of the utterances on top of MultiWOZ 2.1 and redefines the ontology by disallowing vocabularies of slots with a large number of possible values
(e.g., restaurant name, time of booking) and introducing standardized slot span annotations for these slots.
"""
_LICENSE = "Apache License 2.0"
# TODO: Add link to the official dataset URLs here
# The HuggingFace dataset library don't host the datasets but only point to the original files
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
_URL_LIST = [
("dialogue_acts", "https://github.com/budzianowski/multiwoz/raw/master/data/MultiWOZ_2.2/dialog_acts.json")
]
_URL_LIST += [
(
f"train_{i:03d}",
f"https://github.com/budzianowski/multiwoz/raw/master/data/MultiWOZ_2.2/train/dialogues_{i:03d}.json",
)
for i in range(1, 18)
]
_URL_LIST += [
(
f"dev_{i:03d}",
f"https://github.com/budzianowski/multiwoz/raw/master/data/MultiWOZ_2.2/dev/dialogues_{i:03d}.json",
)
for i in range(1, 3)
]
_URL_LIST += [
(
f"test_{i:03d}",
f"https://github.com/budzianowski/multiwoz/raw/master/data/MultiWOZ_2.2/test/dialogues_{i:03d}.json",
)
for i in range(1, 3)
]
_URLs = dict(_URL_LIST)
class MultiWozV22(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("2.2.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="v2.2", version=datasets.Version("2.2.0"), description="MultiWOZ v2.2"),
datasets.BuilderConfig(
name="v2.2_active_only",
version=datasets.Version("2.2.0"),
description="MultiWOZ v2.2, only keeps around frames with an active intent",
),
]
DEFAULT_CONFIG_NAME = "v2.2_active_only"
def _info(self):
features = datasets.Features(
{
"dialogue_id": datasets.Value("string"),
"services": datasets.Sequence(datasets.Value("string")),
"turns": datasets.Sequence(
{
"turn_id": datasets.Value("string"),
"speaker": datasets.ClassLabel(names=["USER", "SYSTEM"]),
"utterance": datasets.Value("string"),
"frames": datasets.Sequence(
{
"service": datasets.Value("string"),
"state": {
"active_intent": datasets.Value("string"),
"requested_slots": datasets.Sequence(datasets.Value("string")),
"slots_values": datasets.Sequence(
{
"slots_values_name": datasets.Value("string"),
"slots_values_list": datasets.Sequence(datasets.Value("string")),
}
),
},
"slots": datasets.Sequence(
{
"slot": datasets.Value("string"),
"value": datasets.Value("string"),
"start": datasets.Value("int32"),
"exclusive_end": datasets.Value("int32"),
"copy_from": datasets.Value("string"),
"copy_from_value": datasets.Sequence(datasets.Value("string")),
}
),
}
),
"dialogue_acts": datasets.Features(
{
"dialog_act": datasets.Sequence(
{
"act_type": datasets.Value("string"),
"act_slots": datasets.Sequence(
datasets.Features(
{
"slot_name": datasets.Value("string"),
"slot_value": datasets.Value("string"),
}
),
),
}
),
"span_info": datasets.Sequence(
{
"act_type": datasets.Value("string"),
"act_slot_name": datasets.Value("string"),
"act_slot_value": datasets.Value("string"),
"span_start": datasets.Value("int32"),
"span_end": datasets.Value("int32"),
}
),
}
),
}
),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features, # Here we define them above because they are different between the two configurations
supervised_keys=None,
homepage="https://github.com/budzianowski/multiwoz/tree/master/data/MultiWOZ_2.2",
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
data_files = dl_manager.download_and_extract(_URLs)
self.stored_dialogue_acts = json.load(open(data_files["dialogue_acts"]))
return [
datasets.SplitGenerator(
name=spl_enum,
gen_kwargs={
"filepaths": data_files,
"split": spl,
},
)
for spl, spl_enum in [
("train", datasets.Split.TRAIN),
("dev", datasets.Split.VALIDATION),
("test", datasets.Split.TEST),
]
]
def _generate_examples(self, filepaths, split):
id_ = -1
file_list = [fpath for fname, fpath in filepaths.items() if fname.startswith(split)]
for filepath in file_list:
dialogues = json.load(open(filepath))
for dialogue in dialogues:
id_ += 1
mapped_acts = self.stored_dialogue_acts.get(dialogue["dialogue_id"], {})
res = {
"dialogue_id": dialogue["dialogue_id"],
"services": dialogue["services"],
"turns": [
{
"turn_id": turn["turn_id"],
"speaker": turn["speaker"],
"utterance": turn["utterance"],
"frames": [
{
"service": frame["service"],
"state": {
"active_intent": frame["state"]["active_intent"] if "state" in frame else "",
"requested_slots": frame["state"]["requested_slots"]
if "state" in frame
else [],
"slots_values": {
"slots_values_name": [
sv_name for sv_name, sv_list in frame["state"]["slot_values"].items()
]
if "state" in frame
else [],
"slots_values_list": [
sv_list for sv_name, sv_list in frame["state"]["slot_values"].items()
]
if "state" in frame
else [],
},
},
"slots": [
{
"slot": slot["slot"],
"value": "" if "copy_from" in slot else slot["value"],
"start": slot.get("start", -1),
"exclusive_end": slot.get("exclusive_end", -1),
"copy_from": slot.get("copy_from", ""),
"copy_from_value": slot["value"] if "copy_from" in slot else [],
}
for slot in frame["slots"]
],
}
for frame in turn["frames"]
if (
"active_only" not in self.config.name
or frame.get("state", {}).get("active_intent", "NONE") != "NONE"
)
],
"dialogue_acts": {
"dialog_act": [
{
"act_type": act_type,
"act_slots": {
"slot_name": [sl_name for sl_name, sl_val in dialog_act],
"slot_value": [sl_val for sl_name, sl_val in dialog_act],
},
}
for act_type, dialog_act in mapped_acts.get(turn["turn_id"], {})
.get("dialog_act", {})
.items()
],
"span_info": [
{
"act_type": span_info[0],
"act_slot_name": span_info[1],
"act_slot_value": span_info[2],
"span_start": span_info[3],
"span_end": span_info[4],
}
for span_info in mapped_acts.get(turn["turn_id"], {}).get("span_info", [])
],
},
}
for turn in dialogue["turns"]
],
}
yield id_, res
|