# 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'])] } }