#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Apr 21 12:49:21 2023 @author: lin.kinwahedward """ #------------------------------------------------------------------------------ # Standard Libraries 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" #------------------------------------------------------------------------------ # Define Dataset Configuration (e.g., subset of dataset, but it is not used here.) 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 #------------------------------------------------------------------------------ # Define Dataset Class 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. 3 Features: 1) path_to_file 2) audio samples 3) emotion label ''' def _info(self): features = datasets.Features( { "path": datasets.Value("string"), "audio": datasets.Audio(sampling_rate = 16000), "label": datasets.ClassLabel( names = [ "neutral", "joy", "sadness", "anger", "surprise", "fear", "disgust" ]) } ) # return dataset info and data feature info return datasets.DatasetInfo( description = _DESCRIPTION, features = features, homepage = _HOMEPAGE, citation = _CITATION, ) #-------------------------------------------------------------------------- def _split_generators(self, dl_manager): 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 ''' 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, { "path": audio_path + filename, # huggingface dataset's will use soundfile to read the audio file "audio": audio_path + filename, "label": emotion, } key += 1 #------------------------------------------------------------------------------