File size: 5,157 Bytes
9de6fa3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c25fac5
9de6fa3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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/projecte-aina/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}