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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
# TODO: Address all TODOs and remove all explanatory comments
|
15 |
+
"""JMultiWOZ: Japanese Multi-Domain Wizard-of-Oz dataset for task-oriented dialogue modelling"""
|
16 |
+
|
17 |
+
import json
|
18 |
+
import os
|
19 |
+
|
20 |
+
import datasets
|
21 |
+
|
22 |
+
|
23 |
+
# TODO: Add BibTeX citation
|
24 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
25 |
+
_CITATION = """\
|
26 |
+
@inproceedings{ohashi-etal-2024-jmultiwoz,
|
27 |
+
title = "JMultiWOZ: A Large-Scale Japanese Multi-Domain Task-Oriented Dialogue Dataset",
|
28 |
+
author = "Ohashi, Atsumoto and Hirai, Ryu and Iizuka, Shinya and Higashinaka, Ryuichiro",
|
29 |
+
booktitle = "Proceedings of the 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation",
|
30 |
+
year = "2024",
|
31 |
+
url = "",
|
32 |
+
pages = "",
|
33 |
+
}
|
34 |
+
"""
|
35 |
+
|
36 |
+
# TODO: Add description of the dataset here
|
37 |
+
# You can copy an official description
|
38 |
+
_DESCRIPTION = """\
|
39 |
+
JMultiWOZ is a large-scale Japanese multi-domain task-oriented dialogue dataset. The dataset is collected using
|
40 |
+
the Wizard-of-Oz (WoZ) methodology, where two human annotators simulate the user and the system. The dataset contains
|
41 |
+
4,264 dialogues across 6 domains, including restaurant, hotel, attraction, shopping, taxi, and weather.
|
42 |
+
"""
|
43 |
+
|
44 |
+
# TODO: Add a link to an official homepage for the dataset here
|
45 |
+
_HOMEPAGE = "https://github.com/nu-dialogue/jmultiwoz"
|
46 |
+
|
47 |
+
# TODO: Add the licence for the dataset here if you can find it
|
48 |
+
_LICENSE = "CC BY-ND 4.0"
|
49 |
+
|
50 |
+
# TODO: Add link to the official dataset URLs here
|
51 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
52 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
53 |
+
_URLS = {
|
54 |
+
"original_zip": "https://github.com/ohashi56225/jmultiwoz-evaluation/blob/master/dataset/JMultiWOZ_1.0.zip",
|
55 |
+
}
|
56 |
+
|
57 |
+
|
58 |
+
def _flatten_value(values):
|
59 |
+
if not isinstance(values, list):
|
60 |
+
return values
|
61 |
+
flat_values = [
|
62 |
+
_flatten_value(v) if isinstance(v, list) else v for v in values
|
63 |
+
]
|
64 |
+
return "[" + ", ".join(flat_values) + "]"
|
65 |
+
|
66 |
+
# TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
|
67 |
+
class JMultiWOZDataset(datasets.GeneratorBasedBuilder):
|
68 |
+
VERSION = datasets.Version("1.0.0")
|
69 |
+
|
70 |
+
def _info(self):
|
71 |
+
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
72 |
+
features = datasets.Features({
|
73 |
+
"dialogue_id": datasets.Value("int32"),
|
74 |
+
"dialogue_name": datasets.Value("string"),
|
75 |
+
"system_name": datasets.Value("string"),
|
76 |
+
"user_name": datasets.Value("string"),
|
77 |
+
"goal": datasets.Sequence({
|
78 |
+
"domain": datasets.Value("string"),
|
79 |
+
"task": datasets.Value("string"),
|
80 |
+
"slot": datasets.Value("string"),
|
81 |
+
"value": datasets.Value("string"),
|
82 |
+
}),
|
83 |
+
"goal_description": datasets.Sequence({
|
84 |
+
"domain": datasets.Value("string"),
|
85 |
+
"text": datasets.Value("string"),
|
86 |
+
}),
|
87 |
+
"turns": datasets.Sequence({
|
88 |
+
"turn_id": datasets.Value("int32"),
|
89 |
+
"speaker": datasets.Value("string"),
|
90 |
+
"utterance": datasets.Value("string"),
|
91 |
+
"dialogue_state": {
|
92 |
+
"belief_state": datasets.Sequence({
|
93 |
+
"domain": datasets.Value("string"),
|
94 |
+
"slot": datasets.Value("string"),
|
95 |
+
"value": datasets.Value("string"),
|
96 |
+
}),
|
97 |
+
"book_state": datasets.Sequence({
|
98 |
+
"domain": datasets.Value("string"),
|
99 |
+
"slot": datasets.Value("string"),
|
100 |
+
"value": datasets.Value("string"),
|
101 |
+
}),
|
102 |
+
"db_result": datasets.Sequence({
|
103 |
+
"candidate_entities": datasets.Sequence(datasets.Value("string")),
|
104 |
+
"active_entity": datasets.Sequence({
|
105 |
+
"slot": datasets.Value("string"),
|
106 |
+
"value": datasets.Value("string"),
|
107 |
+
})
|
108 |
+
}),
|
109 |
+
"book_result": datasets.Sequence({
|
110 |
+
"domain": datasets.Value("string"),
|
111 |
+
"success": datasets.Value("string"),
|
112 |
+
"ref": datasets.Value("string"),
|
113 |
+
}),
|
114 |
+
}
|
115 |
+
}),
|
116 |
+
})
|
117 |
+
|
118 |
+
|
119 |
+
return datasets.DatasetInfo(
|
120 |
+
# This is the description that will appear on the datasets page.
|
121 |
+
description=_DESCRIPTION,
|
122 |
+
# This defines the different columns of the dataset and their types
|
123 |
+
features=features, # Here we define them above because they are different between the two configurations
|
124 |
+
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
125 |
+
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
126 |
+
# supervised_keys=("sentence", "label"),
|
127 |
+
# Homepage of the dataset for documentation
|
128 |
+
homepage=_HOMEPAGE,
|
129 |
+
# License for the dataset if available
|
130 |
+
license=_LICENSE,
|
131 |
+
# Citation for the dataset
|
132 |
+
citation=_CITATION,
|
133 |
+
)
|
134 |
+
|
135 |
+
def _split_generators(self, dl_manager):
|
136 |
+
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
137 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
138 |
+
|
139 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
140 |
+
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
141 |
+
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
142 |
+
data_dir = dl_manager.download_and_extract(_URLS["original_zip"])
|
143 |
+
split_list_path = os.path.join(data_dir, "JMultiWOZ_1.0/split_list.json")
|
144 |
+
dialogues_path = os.path.join(data_dir, "JMultiWOZ_1.0/dialogues.json")
|
145 |
+
with open(split_list_path, "r", encoding="utf-8") as f:
|
146 |
+
split_list = json.load(f)
|
147 |
+
with open(dialogues_path, "r", encoding="utf-8") as f:
|
148 |
+
dialogues = json.load(f)
|
149 |
+
return [
|
150 |
+
datasets.SplitGenerator(
|
151 |
+
name=datasets.Split.TRAIN,
|
152 |
+
# These kwargs will be passed to _generate_examples
|
153 |
+
gen_kwargs={
|
154 |
+
"dialogues": [dialogues[dialogue_name] for dialogue_name in split_list["train"]],
|
155 |
+
"split": "train",
|
156 |
+
},
|
157 |
+
),
|
158 |
+
datasets.SplitGenerator(
|
159 |
+
name=datasets.Split.VALIDATION,
|
160 |
+
# These kwargs will be passed to _generate_examples
|
161 |
+
gen_kwargs={
|
162 |
+
"dialogues": [dialogues[dialogue_name] for dialogue_name in split_list["dev"]],
|
163 |
+
"split": "dev",
|
164 |
+
},
|
165 |
+
),
|
166 |
+
datasets.SplitGenerator(
|
167 |
+
name=datasets.Split.TEST,
|
168 |
+
# These kwargs will be passed to _generate_examples
|
169 |
+
gen_kwargs={
|
170 |
+
"dialogues": [dialogues[dialogue_name] for dialogue_name in split_list["test"]],
|
171 |
+
"split": "test"
|
172 |
+
},
|
173 |
+
),
|
174 |
+
]
|
175 |
+
|
176 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
177 |
+
def _generate_examples(self, dialogues, split):
|
178 |
+
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
179 |
+
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
180 |
+
|
181 |
+
for id_, dialogue in enumerate(dialogues):
|
182 |
+
example = {
|
183 |
+
"dialogue_id": dialogue["dialogue_id"],
|
184 |
+
"dialogue_name": dialogue["dialogue_name"],
|
185 |
+
"system_name": dialogue["system_name"],
|
186 |
+
"user_name": dialogue["user_name"],
|
187 |
+
"goal": [],
|
188 |
+
"goal_description": [],
|
189 |
+
"turns": [],
|
190 |
+
}
|
191 |
+
|
192 |
+
for domain, tasks in dialogue["goal"].items():
|
193 |
+
for task, slot_values in tasks.items():
|
194 |
+
if task == "reqt":
|
195 |
+
slot_values = {slot: None for slot in slot_values}
|
196 |
+
for slot, value in slot_values.items():
|
197 |
+
example["goal"].append({
|
198 |
+
"domain": domain,
|
199 |
+
"task": task,
|
200 |
+
"slot": slot,
|
201 |
+
"value": value,
|
202 |
+
})
|
203 |
+
|
204 |
+
for domain, texts in dialogue["goal_description"].items():
|
205 |
+
for text in texts:
|
206 |
+
example["goal_description"].append({
|
207 |
+
"domain": domain,
|
208 |
+
"text": text,
|
209 |
+
})
|
210 |
+
|
211 |
+
for turn in dialogue["turns"]:
|
212 |
+
example_turn = {
|
213 |
+
"turn_id": turn["turn_id"],
|
214 |
+
"speaker": turn["speaker"],
|
215 |
+
"utterance": turn["utterance"],
|
216 |
+
"dialogue_state": {
|
217 |
+
"belief_state": [],
|
218 |
+
"book_state": [],
|
219 |
+
"db_result": [],
|
220 |
+
"book_result": [],
|
221 |
+
},
|
222 |
+
}
|
223 |
+
if turn["speaker"] == "USER":
|
224 |
+
continue
|
225 |
+
|
226 |
+
for domain, slots in turn["dialogue_state"]["belief_state"].items():
|
227 |
+
for slot, value in slots.items():
|
228 |
+
example_turn["dialogue_state"]["belief_state"].append({
|
229 |
+
"domain": domain,
|
230 |
+
"slot": slot,
|
231 |
+
"value": value,
|
232 |
+
})
|
233 |
+
|
234 |
+
for domain, slots in turn["dialogue_state"]["book_state"].items():
|
235 |
+
for slot, value in slots.items():
|
236 |
+
example_turn["dialogue_state"]["book_state"].append({
|
237 |
+
"domain": domain,
|
238 |
+
"slot": slot,
|
239 |
+
"value": value,
|
240 |
+
})
|
241 |
+
|
242 |
+
candidate_entities = turn["dialogue_state"]["db_result"]["candidate_entities"]
|
243 |
+
active_entity = turn["dialogue_state"]["db_result"]["active_entity"]
|
244 |
+
if not active_entity:
|
245 |
+
active_entity = {}
|
246 |
+
example_turn["dialogue_state"]["db_result"].append({
|
247 |
+
"candidate_entities":candidate_entities,
|
248 |
+
"active_entity": [{
|
249 |
+
"slot": slot,
|
250 |
+
"value": _flatten_value(value),
|
251 |
+
} for slot, value in active_entity.items()]
|
252 |
+
})
|
253 |
+
|
254 |
+
for domain, result in turn["dialogue_state"]["book_result"].items():
|
255 |
+
example_turn["dialogue_state"]["book_result"].append({
|
256 |
+
"domain": domain,
|
257 |
+
"success": result["success"],
|
258 |
+
"ref": result["ref"],
|
259 |
+
})
|
260 |
+
|
261 |
+
example["turns"].append(example_turn)
|
262 |
+
|
263 |
+
yield id_, example
|