Datasets:
ShutongFeng
commited on
Commit
•
d7db67f
1
Parent(s):
1710fcf
Upload emowoz.py
Browse files
emowoz.py
ADDED
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
"""TODO: Add a description here."""
|
16 |
+
|
17 |
+
|
18 |
+
import csv
|
19 |
+
import json
|
20 |
+
import os
|
21 |
+
|
22 |
+
import datasets
|
23 |
+
|
24 |
+
|
25 |
+
# TODO: Add BibTeX citation
|
26 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
27 |
+
_CITATION = """\
|
28 |
+
@inproceedings{feng-etal-2022-emowoz,
|
29 |
+
title = "{E}mo{WOZ}: A Large-Scale Corpus and Labelling Scheme for Emotion Recognition in Task-Oriented Dialogue Systems",
|
30 |
+
author = "Feng, Shutong and
|
31 |
+
Lubis, Nurul and
|
32 |
+
Geishauser, Christian and
|
33 |
+
Lin, Hsien-chin and
|
34 |
+
Heck, Michael and
|
35 |
+
van Niekerk, Carel and
|
36 |
+
Gasic, Milica",
|
37 |
+
booktitle = "Proceedings of the Thirteenth Language Resources and Evaluation Conference",
|
38 |
+
month = jun,
|
39 |
+
year = "2022",
|
40 |
+
address = "Marseille, France",
|
41 |
+
publisher = "European Language Resources Association",
|
42 |
+
url = "https://aclanthology.org/2022.lrec-1.436",
|
43 |
+
pages = "4096--4113",
|
44 |
+
abstract = "The ability to recognise emotions lends a conversational artificial intelligence a human touch. While emotions in chit-chat dialogues have received substantial attention, emotions in task-oriented dialogues remain largely unaddressed. This is despite emotions and dialogue success having equally important roles in a natural system. Existing emotion-annotated task-oriented corpora are limited in size, label richness, and public availability, creating a bottleneck for downstream tasks. To lay a foundation for studies on emotions in task-oriented dialogues, we introduce EmoWOZ, a large-scale manually emotion-annotated corpus of task-oriented dialogues. EmoWOZ is based on MultiWOZ, a multi-domain task-oriented dialogue dataset. It contains more than 11K dialogues with more than 83K emotion annotations of user utterances. In addition to Wizard-of-Oz dialogues from MultiWOZ, we collect human-machine dialogues within the same set of domains to sufficiently cover the space of various emotions that can happen during the lifetime of a data-driven dialogue system. To the best of our knowledge, this is the first large-scale open-source corpus of its kind. We propose a novel emotion labelling scheme, which is tailored to task-oriented dialogues. We report a set of experimental results to show the usability of this corpus for emotion recognition and state tracking in task-oriented dialogues.",
|
45 |
+
}
|
46 |
+
"""
|
47 |
+
|
48 |
+
# TODO: Add description of the dataset here
|
49 |
+
# You can copy an official description
|
50 |
+
_DESCRIPTION = """\
|
51 |
+
EmoWOZ is a user emotion recognition in task-oriented dialogues dataset, \
|
52 |
+
consisting all dialogues from MultiWOZ and 1000 additional human-machine \
|
53 |
+
dialogues (DialMAGE). Each user utterance is annotated with one of the \
|
54 |
+
following emotions: 0: neutral, 1: fearful, 2: dissatisfied, 3: apologetic, \
|
55 |
+
4: abusive, 5: excited, 6: satisfied. System utterances are annotated with \
|
56 |
+
-1. For detailed label design and explanation, please refer to the paper and \
|
57 |
+
dataset homepage.
|
58 |
+
"""
|
59 |
+
|
60 |
+
# TODO: Add a link to an official homepage for the dataset here
|
61 |
+
_HOMEPAGE = "https://zenodo.org/record/6506504"
|
62 |
+
|
63 |
+
# TODO: Add the licence for the dataset here if you can find it
|
64 |
+
_LICENSE = "https://creativecommons.org/licenses/by-nc/4.0/legalcode"
|
65 |
+
|
66 |
+
# TODO: Add link to the official dataset URLs here
|
67 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
68 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
69 |
+
_URLS = {
|
70 |
+
"emowoz_multiwoz": "https://zenodo.org/record/6506504/files/emowoz-multiwoz.json",
|
71 |
+
"emowoz_dialmage": "https://zenodo.org/record/6506504/files/emowoz-dialmage.json",
|
72 |
+
"emowoz_split": "https://zenodo.org/record/6506504/files/data-split.json"
|
73 |
+
}
|
74 |
+
|
75 |
+
|
76 |
+
|
77 |
+
class EmoWOZ(datasets.GeneratorBasedBuilder):
|
78 |
+
"""EmoWOZ: A Large-Scale Corpus and Labelling Scheme for Emotion Recognition in Task-Oriented Dialogue Systems"""
|
79 |
+
|
80 |
+
VERSION = datasets.Version("1.0.0")
|
81 |
+
|
82 |
+
# This is an example of a dataset with multiple configurations.
|
83 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
84 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
85 |
+
|
86 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
87 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
88 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
89 |
+
|
90 |
+
# You will be able to load one or the other configurations in the following list with
|
91 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
92 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
93 |
+
BUILDER_CONFIGS = [
|
94 |
+
datasets.BuilderConfig(name="train-all", version=VERSION, description="This part contains the training set of all user-emotion-annotated dialogues from EmoWOZ"),
|
95 |
+
datasets.BuilderConfig(name="dev-all", version=VERSION, description="This part contains the development set of all user-emotion-annotated dialogues from EmoWOZ"),
|
96 |
+
datasets.BuilderConfig(name="test-all", version=VERSION, description="This part contains the test set of all user-emotion-annotated dialogues from EmoWOZ"),
|
97 |
+
datasets.BuilderConfig(name="train-multiwoz", version=VERSION, description="This part contains the training set of user-emotion-annotated dialogues from MultiWOZ"),
|
98 |
+
datasets.BuilderConfig(name="dev-multiwoz", version=VERSION, description="This part contains the development set of user-emotion-annotated dialogues from MultiWOZ"),
|
99 |
+
datasets.BuilderConfig(name="test-multiwoz", version=VERSION, description="This part contains the test set of user-emotion-annotated dialogues from MultiWOZ"),
|
100 |
+
datasets.BuilderConfig(name="train-dialmage", version=VERSION, description="This part contains the training set of user-emotion-annotated dialogues from human-machine interaction (DialMAGE)"),
|
101 |
+
datasets.BuilderConfig(name="dev-dialmage", version=VERSION, description="This part contains the development set of user-emotion-annotated dialogues from human-machine interaction (DialMAGE)"),
|
102 |
+
datasets.BuilderConfig(name="test-dialmage", version=VERSION, description="This part contains the test set of user-emotion-annotated dialogues from human-machine interaction (DialMAGE)"),
|
103 |
+
]
|
104 |
+
|
105 |
+
# DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
106 |
+
|
107 |
+
def _info(self):
|
108 |
+
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
109 |
+
|
110 |
+
features = datasets.Features(
|
111 |
+
{
|
112 |
+
"dialogue_id": datasets.Value("string"),
|
113 |
+
"log": datasets.features.Sequence(
|
114 |
+
{
|
115 |
+
"text": datasets.Value("string"),
|
116 |
+
"emotion": datasets.ClassLabel(names=[-1,0,1,2,3,4,5,6])
|
117 |
+
}
|
118 |
+
)
|
119 |
+
}
|
120 |
+
)
|
121 |
+
|
122 |
+
return datasets.DatasetInfo(
|
123 |
+
description=_DESCRIPTION,
|
124 |
+
features=features,
|
125 |
+
homepage=_HOMEPAGE,
|
126 |
+
license=_LICENSE,
|
127 |
+
citation=_CITATION,
|
128 |
+
)
|
129 |
+
|
130 |
+
def _split_generators(self, dl_manager):
|
131 |
+
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
132 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
133 |
+
|
134 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
135 |
+
# 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.
|
136 |
+
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
137 |
+
data_dir = dl_manager.download_and_extract(_URLS)
|
138 |
+
|
139 |
+
urls = _URLS[self.config.name]
|
140 |
+
|
141 |
+
return [
|
142 |
+
datasets.SplitGenerator(
|
143 |
+
name=datasets.Split.TRAIN,
|
144 |
+
# These kwargs will be passed to _generate_examples
|
145 |
+
gen_kwargs={
|
146 |
+
"multiwoz_filepath": data_dir['emowoz_multiwoz'],
|
147 |
+
"dialmage_filepath": data_dir['emowoz_dialmage'],
|
148 |
+
"split_filepath": data_dir['emowoz_split'],
|
149 |
+
},
|
150 |
+
),
|
151 |
+
datasets.SplitGenerator(
|
152 |
+
name=datasets.Split.VALIDATION,
|
153 |
+
# These kwargs will be passed to _generate_examples
|
154 |
+
gen_kwargs={
|
155 |
+
"multiwoz_filepath": data_dir['emowoz_multiwoz'],
|
156 |
+
"dialmage_filepath": data_dir['emowoz_dialmage'],
|
157 |
+
"split_filepath": data_dir['emowoz_split'],
|
158 |
+
},
|
159 |
+
),
|
160 |
+
datasets.SplitGenerator(
|
161 |
+
name=datasets.Split.TEST,
|
162 |
+
# These kwargs will be passed to _generate_examples
|
163 |
+
gen_kwargs={
|
164 |
+
"multiwoz_filepath": data_dir['emowoz_multiwoz'],
|
165 |
+
"dialmage_filepath": data_dir['emowoz_dialmage'],
|
166 |
+
"split_filepath": data_dir['emowoz_split'],
|
167 |
+
},
|
168 |
+
),
|
169 |
+
]
|
170 |
+
|
171 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
172 |
+
def _generate_examples(self, multiwoz_filepath, dialmage_filepath, split_filepath):
|
173 |
+
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
174 |
+
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
175 |
+
with open(multiwoz_filepath, encoding="utf-8") as f:
|
176 |
+
multiwoz_dialogues = json.load(f)
|
177 |
+
with open(dialmage_filepath, encoding="utf-8") as f:
|
178 |
+
dialmage_dialogues = json.load(f)
|
179 |
+
dialogues = {**multiwoz_dialogues, **dialmage_dialogues}
|
180 |
+
|
181 |
+
with open(split_filepath, encoding="utf-8") as f:
|
182 |
+
data_split = json.load(f)
|
183 |
+
|
184 |
+
split, subset = self.config.name.split('-')
|
185 |
+
if subset == 'all':
|
186 |
+
dial_ids = data_split[split]['multiwoz'] + data_split[split]['dialmage']
|
187 |
+
else:
|
188 |
+
dial_ids = data_split[split][subset]
|
189 |
+
|
190 |
+
for key in dial_ids:
|
191 |
+
yield key, {
|
192 |
+
"dialogue_id": key,
|
193 |
+
"log": {
|
194 |
+
"text": [log['text'] for log in dialogues[key]['log']],
|
195 |
+
"emotion": [a['emotion'][3]["emotion"] if i%2 == 0 else -1 for i, a in enumerate(dialogues[key]['log'])]
|
196 |
+
}
|
197 |
+
}
|