parlament_parla / parlament_parla.py
albertvillanova's picture
Add dataset loading script
9de6fa3
raw
history blame
5.16 kB
# coding=utf-8
# 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.
"""ParlamentParla - Speech corpus of Catalan Parliamentary sessions."""
import pandas as pd
import datasets
from datasets.tasks import AutomaticSpeechRecognition
_CITATION = """\
@dataset{kulebi_baybars_2021_5541827,
author = {Külebi, Baybars},
title = {{ParlamentParla - Speech corpus of Catalan
Parliamentary sessions}},
month = oct,
year = 2021,
publisher = {Zenodo},
version = {v2.0},
doi = {10.5281/zenodo.5541827},
url = {https://doi.org/10.5281/zenodo.5541827}
}
"""
_DESCRIPTION = """\
This is the ParlamentParla speech corpus for Catalan prepared by Col·lectivaT. The audio segments were extracted from recordings the Catalan Parliament (Parlament de Catalunya) plenary sessions, which took place between 2007/07/11 - 2018/07/17. We aligned the transcriptions with the recordings and extracted the corpus. The content belongs to the Catalan Parliament and the data is released conforming their terms of use.
Preparation of this corpus was partly supported by the Department of Culture of the Catalan autonomous government, and the v2.0 was supported by the Barcelona Supercomputing Center, within the framework of the project AINA of the Departament de Polítiques Digitals.
As of v2.0 the corpus is separated into 211 hours of clean and 400 hours of other quality segments. Furthermore, each speech segment is tagged with its speaker and each speaker with their gender. The statistics are detailed in the readme file.
For more information, go to https://github.com/CollectivaT-dev/ParlamentParla or mail info@collectivat.cat.
"""
_HOMEPAGE = "https://zenodo.org/record/5541827"
_LICENSE = "Creative Commons Attribution 4.0 International"
_INDEX_REPO = "https://huggingface.co/datasets/albertvillanova/parlament_parla/resolve/main/"
_URLS = {
"index": _INDEX_REPO + "data/{config}/{split}/{config}_{split}.tsv",
"audio": "https://zenodo.org/record/5541827/files/{config}_{split}.tar.gz?download=1",
}
_SPLITS = {datasets.Split.TRAIN: "train", datasets.Split.VALIDATION: "dev", datasets.Split.TEST: "test"}
class ParlamentParla(datasets.GeneratorBasedBuilder):
"""ParlamentParla."""
VERSION = datasets.Version("2.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="clean", version=VERSION, description="211 hours of clean quality segments."),
datasets.BuilderConfig(name="other", version=VERSION, description="400 hours of other quality segments."),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"path": datasets.Value("string"),
"audio": datasets.features.Audio(),
"speaker_id": datasets.Value("int64"),
"sentence": datasets.Value("string"),
"gender": datasets.ClassLabel(names=["F", "M"]),
"duration": datasets.Value("float64"),
}
),
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
task_templates=[
AutomaticSpeechRecognition(audio_file_path_column="path", transcription_column="sentence")
],
)
def _split_generators(self, dl_manager):
urls = {
split: {key: url.format(config=self.config.name, split=_SPLITS[split]) for key, url in _URLS.items()}
for split in _SPLITS
}
dl_dir = dl_manager.download(urls)
return [
datasets.SplitGenerator(
name=split,
gen_kwargs={
"index_path": dl_dir[split]["index"],
"audio_files": dl_manager.iter_archive(dl_dir[split]["audio"]),
},
)
for split in _SPLITS
]
def _generate_examples(self, index_path, audio_files):
with open(index_path, encoding="utf-8") as index_file:
index = pd.read_csv(index_file, delimiter="\t", index_col="path").to_dict(orient="index")
# clean: 83568 = 79269 + 2155 + 2144 ; other: 146669 = 142813 + 1957 + 1899
for key, (path, file) in enumerate(audio_files):
if path.endswith(".wav"):
data = index.pop(path)
audio = {"path": path, "bytes": file.read()}
yield key, {"path": path, "audio": audio, **data}