Datasets:

Modalities:
Audio
Text
Languages:
Yue Chinese
ArXiv:
Libraries:
Datasets
License:
YueMotion / YueMotion.py
holylovenia's picture
Add dataloader
48c5ff8
# coding=utf-8
# Copyright 2021 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.
""" Common Voice Dataset"""
from datasets import AutomaticSpeechRecognition
import datasets
import os
import pandas as pd
_CITATION = """\
@misc{cahyawijaya2023crosslingual,
title={Cross-Lingual Cross-Age Group Adaptation for Low-Resource Elderly Speech Emotion Recognition},
author={Samuel Cahyawijaya and Holy Lovenia and Willy Chung and Rita Frieske and Zihan Liu and Pascale Fung},
year={2023},
eprint={2306.14517},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
"""
_DESCRIPTION = """\
YueMotion is a Cantonese speech emotion dataset.
"""
_HOMEPAGE = "https://huggingface.co/datasets/CAiRE/YueMotion"
_URL = "https://huggingface.co/datasets/CAiRE/YueMotion/raw/main/"
_URLS = {
"train": _URL + "train_metadata.csv",
"test": _URL + "test_metadata.csv",
"validation": _URL + "validation_metadata.csv",
"waves": "https://huggingface.co/datasets/CAiRE/YueMotion/resolve/main/data.tar.bz2",
}
class YueMotionConfig(datasets.BuilderConfig):
"""BuilderConfig for YueMotion."""
def __init__(self, name="main", **kwargs):
"""
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(YueMotionConfig, self).__init__(name, **kwargs)
class YueMotion(datasets.GeneratorBasedBuilder):
"""YueMotion: Cantonese speech emotion recognition for both adults and elderly. Snapshot date: 28 June 2023."""
BUILDER_CONFIGS = [
YueMotionConfig(
name="main",
version=datasets.Version("1.0.0", ""),
description=_DESCRIPTION,
)
]
def _info(self):
features = datasets.Features(
{
"split": datasets.Value("string"),
"speaker_id": datasets.Value("string"),
"path": datasets.Value("string"),
"audio": datasets.Audio(sampling_rate=16_000),
"gender": datasets.Value("string"),
"age": datasets.Value("int64"),
"sentence_id": datasets.Value("string"),
"label_id": datasets.Value("int64"),
"label": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
citation=_CITATION,
task_templates=[AutomaticSpeechRecognition(audio_column="audio", transcription_column="transcription")],
)
def _split_generators(self, dl_manager):
downloaded_files = dl_manager.download_and_extract(_URLS)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"metadata_path": downloaded_files["train"],
"wave_path": downloaded_files["waves"],
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"metadata_path": downloaded_files["test"],
"wave_path": downloaded_files["waves"],
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"metadata_path": downloaded_files["validation"],
"wave_path": downloaded_files["waves"],
},
),
]
def _generate_examples(self, metadata_path, wave_path):
print(metadata_path)
metadata_df = pd.read_csv(metadata_path)
for index, row in metadata_df.iterrows():
example = {
"split": row["split"],
"speaker_id": row["speaker_id"],
"path": os.path.join(wave_path, row["file_name"]),
"audio": os.path.join(wave_path, row["file_name"]),
"gender": row["gender"],
"age": row["age"],
"sentence_id": row["sentence_id"],
"label_id": row["label_id"],
"label": row["label"],
}
yield index, example