| |
| |
| """ |
| Created on Mon Apr 24 10:45:46 2023 |
| |
| @author: lin.kinwahedward |
| """ |
| |
| |
| import datasets |
| import csv |
| |
| """The Audio, Speech, and Vision Processing Lab - Emotional Sound Database (ASVP - ESD)""" |
|
|
| _CITATION = """\ |
| @article{poria2018meld, |
| title={Meld: A multimodal multi-party dataset for emotion recognition in conversations}, |
| author={Poria, Soujanya and Hazarika, Devamanyu and Majumder, Navonil and Naik, Gautam and Cambria, Erik and Mihalcea, Rada}, |
| journal={arXiv preprint arXiv:1810.02508}, |
| year={2018} |
| } |
| @article{chen2018emotionlines, |
| title={Emotionlines: An emotion corpus of multi-party conversations}, |
| author={Chen, Sheng-Yeh and Hsu, Chao-Chun and Kuo, Chuan-Chun and Ku, Lun-Wei and others}, |
| journal={arXiv preprint arXiv:1802.08379}, |
| year={2018} |
| } |
| """ |
|
|
| _DESCRIPTION = """\ |
| Multimodal EmotionLines Dataset (MELD) has been created by enhancing and extending EmotionLines dataset. |
| MELD contains the same dialogue instances available in EmotionLines, but it also encompasses audio and |
| visual modality along with text. MELD has more than 1400 dialogues and 13000 utterances from Friends TV series. |
| Multiple speakers participated in the dialogues. Each utterance in a dialogue has been labeled by any of these |
| seven emotions -- Anger, Disgust, Sadness, Joy, Neutral, Surprise and Fear. MELD also has sentiment (positive, |
| negative and neutral) annotation for each utterance. |
| |
| This dataset is slightly modified, so that it concentrates on Emotion recognition in audio input only. |
| """ |
|
|
| _HOMEPAGE = "https://affective-meld.github.io/" |
|
|
| _LICENSE = "CC BY 4.0" |
|
|
| |
| _DATA_URL = "https://drive.google.com/uc?export=download&id=1TPr9v5Vz1qQuxPWcr8RedfuQvLyuG1lm" |
|
|
| |
| |
| class DS_Config(datasets.BuilderConfig): |
| |
| def __init__(self, name, description, homepage, data_url): |
| |
| super(DS_Config, self).__init__( |
| name = self.name, |
| version = datasets.Version("1.0.0"), |
| description = self.description, |
| ) |
| self.name = name |
| self.description = description |
| self.homepage = homepage |
| self.data_url = data_url |
| |
| |
| class MELD_Audio(datasets.GeneratorBasedBuilder): |
| |
| BUILDER_CONFIGS = [DS_Config( |
| name = "MELD_Audio", |
| description = _DESCRIPTION, |
| homepage = _HOMEPAGE, |
| data_url = _DATA_URL |
| )] |
| |
| ''' |
| Define the "column header" (feature) of a datum. |
| 2 Features: |
| 1) audio samples |
| 2) emotion label |
| ''' |
| def _info(self): |
| |
| features = datasets.Features( |
| { |
| "audio": datasets.Audio(sampling_rate = 16000), |
| "label": datasets.ClassLabel( |
| names = [ |
| "neutral", |
| "joy", |
| "sadness", |
| "anger", |
| "surprise", |
| "fear", |
| "disgust" |
| ]) |
| } |
| ) |
| |
| |
| return datasets.DatasetInfo( |
| description = _DESCRIPTION, |
| features = features, |
| homepage = _HOMEPAGE, |
| citation = _CITATION, |
| ) |
| |
| def _split_generators(self, dl_manager): |
| ''' |
| Split the dataset into datasets.Split.{"TRAIN", "VALIDATION", "TEST", "ALL"} |
| |
| The dataset can be further modified, please see below link for details. |
| https://huggingface.co/docs/datasets/process |
| ''' |
| |
| |
| dataset_path = dl_manager.download_and_extract(self.config.data_url) |
| |
| |
| return [ |
| datasets.SplitGenerator( |
| name = datasets.Split.TRAIN, |
| gen_kwargs = {"audio_path": dataset_path + "/MELD-Audio/train/", |
| "csv_path": dataset_path + "/MELD-Audio/train.csv" |
| }, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.VALIDATION, |
| gen_kwargs = {"audio_path": dataset_path + "/MELD-Audio/dev/", |
| "csv_path": dataset_path + "/MELD-Audio/dev.csv" |
| }, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.TEST, |
| gen_kwargs = {"audio_path": dataset_path + "/MELD-Audio/test/", |
| "csv_path": dataset_path + "/MELD-Audio/test.csv" |
| }, |
| ), |
| ] |
| |
| def _generate_examples(self, audio_path, csv_path): |
| ''' |
| Get the audio file and set the corresponding labels |
| |
| Must execute till yield, otherwise, error will occur! |
| ''' |
| key = 0 |
| with open(csv_path, encoding = "utf-8") as csv_file: |
| csv_reader = csv.reader(csv_file, delimiter = ",", skipinitialspace=True) |
| next(csv_reader) |
| for row in csv_reader: |
| _, _, _, emotion, _, dialogue_id, utterance_id, _, _, _, _ = row |
| filename = "dia" + dialogue_id + "_utt" + utterance_id + ".mp3" |
| yield key, { |
| |
| "audio": audio_path + filename, |
| "label": emotion, |
| } |
| key += 1 |
| |
|
|