File size: 6,690 Bytes
28d14c9 a263eb7 28d14c9 a263eb7 28d14c9 a263eb7 28d14c9 a263eb7 28d14c9 a263eb7 28d14c9 a263eb7 28d14c9 fd950f4 28d14c9 fd950f4 28d14c9 fd950f4 28d14c9 fd950f4 28d14c9 a263eb7 28d14c9 fd950f4 28d14c9 fd950f4 28d14c9 fd950f4 28d14c9 |
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 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 24 10:45:46 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"
# The actual place where the data is stored!
_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.
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 dataset info and data feature info
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
'''
# Get the dataset and store at the machine where this script is executed!
dataset_path = dl_manager.download_and_extract(self.config.data_url)
# "audio_path" and "csv_path" would be the parameters passed to def _generate_examples()
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, {
# huggingface dataset's will use soundfile to read the audio file
"audio": audio_path + filename,
"label": emotion,
}
key += 1
#------------------------------------------------------------------------------
|