File size: 7,640 Bytes
d7db67f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de988d8
 
 
 
 
 
 
 
 
 
 
 
 
 
d7db67f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5638297
9b592da
 
d7db67f
 
de988d8
d7db67f
de988d8
 
 
d7db67f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de988d8
d7db67f
de988d8
d7db67f
9064f2a
d7db67f
 
 
 
 
 
 
0315ca1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7db67f
1f0b623
d7db67f
 
de988d8
0315ca1
de988d8
d7db67f
 
 
 
 
 
 
 
 
5638297
d7db67f
 
9b592da
d7db67f
9b592da
d31e9c0
634ad4b
d7db67f
 
 
 
 
 
 
 
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
# 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.


import json

import datasets


_CITATION = """\
@inproceedings{feng-etal-2022-emowoz,
    title = "{E}mo{WOZ}: A Large-Scale Corpus and Labelling Scheme for Emotion Recognition in Task-Oriented Dialogue Systems",
    author = "Feng, Shutong  and
      Lubis, Nurul  and
      Geishauser, Christian  and
      Lin, Hsien-chin  and
      Heck, Michael  and
      van Niekerk, Carel  and
      Gasic, Milica",
    booktitle = "Proceedings of the Thirteenth Language Resources and Evaluation Conference",
    month = jun,
    year = "2022",
    address = "Marseille, France",
    publisher = "European Language Resources Association",
    url = "https://aclanthology.org/2022.lrec-1.436",
    pages = "4096--4113",
    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.",
}
"""

_DESCRIPTION = """\
EmoWOZ is a user emotion recognition in task-oriented dialogues dataset, \
consisting all dialogues from MultiWOZ and 1000 additional human-machine \
dialogues (DialMAGE). Each user utterance is annotated with one of the \
following emotions: 0: neutral, 1: fearful, 2: dissatisfied, 3: apologetic, \
4: abusive, 5: excited, 6: satisfied. System utterances are annotated with \
-1. For detailed label design and explanation, please refer to the paper and \
dataset homepage.
"""

_HOMEPAGE = "https://zenodo.org/record/6506504"

_LICENSE = "https://creativecommons.org/licenses/by-nc/4.0/legalcode"

_URLS = {
    "emowoz_multiwoz": "https://zenodo.org/record/6506504/files/emowoz-multiwoz.json",
    "emowoz_dialmage": "https://zenodo.org/record/6506504/files/emowoz-dialmage.json",
    "emowoz_split": "https://zenodo.org/record/6506504/files/data-split.json"
}


class EmoWOZ(datasets.GeneratorBasedBuilder):
    """EmoWOZ: A Large-Scale Corpus and Labelling Scheme for Emotion Recognition in Task-Oriented Dialogue Systems"""

    VERSION = datasets.Version("1.0.0")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name="emowoz", version=VERSION, description="This part contains all user-emotion-annotated dialogues from EmoWOZ"),
        datasets.BuilderConfig(name="multiwoz", version=VERSION, description="This part contains all user-emotion-annotated dialogues from MultiWOZ"),
        datasets.BuilderConfig(name="dialmage", version=VERSION, description="This part contains all user-emotion-annotated dialogues from human-machine interactions (DialMAGE)"),
    ]

    DEFAULT_CONFIG_NAME = "emowoz"

    
    def _info(self):     
        
        features = datasets.Features(
            {
                "dialogue_id": datasets.Value("string"),
                "log": datasets.features.Sequence(
                    {
                        "text": datasets.Value("string"),
                        "emotion": datasets.ClassLabel(names=[-1,0,1,2,3,4,5,6])
                    }
                )
            }
        )
        
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    
    def _split_generators(self, dl_manager):
        
        data_dir = dl_manager.download_and_extract(_URLS)
                
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "multiwoz_filepath": data_dir['emowoz_multiwoz'],
                    "dialmage_filepath": data_dir['emowoz_dialmage'],
                    "split_filepath": data_dir['emowoz_split'],
                    "split": "train"
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "multiwoz_filepath": data_dir['emowoz_multiwoz'],
                    "dialmage_filepath": data_dir['emowoz_dialmage'],
                    "split_filepath": data_dir['emowoz_split'],
                    "split": "dev"
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "multiwoz_filepath": data_dir['emowoz_multiwoz'],
                    "dialmage_filepath": data_dir['emowoz_dialmage'],
                    "split_filepath": data_dir['emowoz_split'],
                    "split": "test"
                },
            )
        ]


    def _generate_examples(self, multiwoz_filepath, dialmage_filepath, split_filepath, split):
        
        with open(multiwoz_filepath, encoding="utf-8") as f:
            multiwoz_dialogues = json.load(f)
        with open(dialmage_filepath, encoding="utf-8") as f:
            dialmage_dialogues = json.load(f)
        dialogues = {**multiwoz_dialogues, **dialmage_dialogues}

        with open(split_filepath, encoding="utf-8") as f:
            data_split = json.load(f)
        
        if self.config.name == 'emowoz':
            dial_ids = data_split[split]['multiwoz'] + data_split[split]['dialmage']
        else:
            dial_ids = data_split[split][self.config.name]

        # resolve the one duplicate key in the training set of emowoz/data-split.json
        dial_ids = list(set(dial_ids))
                        
        for key in dial_ids:
            yield key, {
                "dialogue_id": key,
                "log": {
                    "text": [log['text'] for log in dialogues[key]['log']],
                    "emotion": [a['emotion'][3]["emotion"] if i%2 == 0 else -1 for i, a in enumerate(dialogues[key]['log'])]
                }
            }