# 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. # TODO: Address all TODOs and remove all explanatory comments """TODO: Add a description here.""" import csv import json import os import datasets # TODO: Add BibTeX citation # Find for instance the citation on arxiv or on the dataset repo/website _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.", } """ # TODO: Add description of the dataset here # You can copy an official description _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. """ # TODO: Add a link to an official homepage for the dataset here _HOMEPAGE = "https://zenodo.org/record/6506504" # TODO: Add the licence for the dataset here if you can find it _LICENSE = "https://creativecommons.org/licenses/by-nc/4.0/legalcode" # TODO: Add link to the official dataset URLs here # The HuggingFace Datasets library doesn't host the datasets but only points to the original files. # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method) _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") # This is an example of a dataset with multiple configurations. # If you don't want/need to define several sub-sets in your dataset, # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes. # If you need to make complex sub-parts in the datasets with configurable options # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig # BUILDER_CONFIG_CLASS = MyBuilderConfig # You will be able to load one or the other configurations in the following list with # data = datasets.load_dataset('my_dataset', 'first_domain') # data = datasets.load_dataset('my_dataset', 'second_domain') BUILDER_CONFIGS = [ datasets.BuilderConfig(name="train-all", version=VERSION, description="This part contains the training set of all user-emotion-annotated dialogues from EmoWOZ"), datasets.BuilderConfig(name="dev-all", version=VERSION, description="This part contains the development set of all user-emotion-annotated dialogues from EmoWOZ"), datasets.BuilderConfig(name="test-all", version=VERSION, description="This part contains the test set of all user-emotion-annotated dialogues from EmoWOZ"), datasets.BuilderConfig(name="train-multiwoz", version=VERSION, description="This part contains the training set of user-emotion-annotated dialogues from MultiWOZ"), datasets.BuilderConfig(name="dev-multiwoz", version=VERSION, description="This part contains the development set of user-emotion-annotated dialogues from MultiWOZ"), datasets.BuilderConfig(name="test-multiwoz", version=VERSION, description="This part contains the test set of user-emotion-annotated dialogues from MultiWOZ"), datasets.BuilderConfig(name="train-dialmage", version=VERSION, description="This part contains the training set of user-emotion-annotated dialogues from human-machine interaction (DialMAGE)"), datasets.BuilderConfig(name="dev-dialmage", version=VERSION, description="This part contains the development set of user-emotion-annotated dialogues from human-machine interaction (DialMAGE)"), datasets.BuilderConfig(name="test-dialmage", version=VERSION, description="This part contains the test set of user-emotion-annotated dialogues from human-machine interaction (DialMAGE)"), ] # DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense. def _info(self): # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset 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): # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS # 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. # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive data_dir = dl_manager.download_and_extract(_URLS) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, # These kwargs will be passed to _generate_examples gen_kwargs={ "multiwoz_filepath": data_dir['emowoz_multiwoz'], "dialmage_filepath": data_dir['emowoz_dialmage'], "split_filepath": data_dir['emowoz_split'], }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, # These kwargs will be passed to _generate_examples gen_kwargs={ "multiwoz_filepath": data_dir['emowoz_multiwoz'], "dialmage_filepath": data_dir['emowoz_dialmage'], "split_filepath": data_dir['emowoz_split'], }, ), datasets.SplitGenerator( name=datasets.Split.TEST, # These kwargs will be passed to _generate_examples gen_kwargs={ "multiwoz_filepath": data_dir['emowoz_multiwoz'], "dialmage_filepath": data_dir['emowoz_dialmage'], "split_filepath": data_dir['emowoz_split'], }, ), ] # method parameters are unpacked from `gen_kwargs` as given in `_split_generators` def _generate_examples(self, multiwoz_filepath, dialmage_filepath, split_filepath): # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset. # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example. 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) split, subset = self.config.name.split('-') if subset == 'all': dial_ids = data_split[split]['multiwoz'] + data_split[split]['dialmage'] else: dial_ids = data_split[split][subset] 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'])] } }