albertvillanova HF staff commited on
Commit
9de6fa3
1 Parent(s): 55de075

Add dataset loading script

Browse files
Files changed (1) hide show
  1. parlament_parla.py +116 -0
parlament_parla.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """ParlamentParla - Speech corpus of Catalan Parliamentary sessions."""
16
+
17
+ import pandas as pd
18
+
19
+ import datasets
20
+ from datasets.tasks import AutomaticSpeechRecognition
21
+
22
+
23
+ _CITATION = """\
24
+ @dataset{kulebi_baybars_2021_5541827,
25
+ author = {Külebi, Baybars},
26
+ title = {{ParlamentParla - Speech corpus of Catalan
27
+ Parliamentary sessions}},
28
+ month = oct,
29
+ year = 2021,
30
+ publisher = {Zenodo},
31
+ version = {v2.0},
32
+ doi = {10.5281/zenodo.5541827},
33
+ url = {https://doi.org/10.5281/zenodo.5541827}
34
+ }
35
+ """
36
+
37
+ _DESCRIPTION = """\
38
+ 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.
39
+
40
+ 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.
41
+
42
+ 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.
43
+
44
+ For more information, go to https://github.com/CollectivaT-dev/ParlamentParla or mail info@collectivat.cat.
45
+ """
46
+
47
+ _HOMEPAGE = "https://zenodo.org/record/5541827"
48
+
49
+ _LICENSE = "Creative Commons Attribution 4.0 International"
50
+
51
+ _INDEX_REPO = "https://huggingface.co/datasets/albertvillanova/parlament_parla/resolve/main/"
52
+ _URLS = {
53
+ "index": _INDEX_REPO + "data/{config}/{split}/{config}_{split}.tsv",
54
+ "audio": "https://zenodo.org/record/5541827/files/{config}_{split}.tar.gz?download=1",
55
+ }
56
+ _SPLITS = {datasets.Split.TRAIN: "train", datasets.Split.VALIDATION: "dev", datasets.Split.TEST: "test"}
57
+
58
+
59
+ class ParlamentParla(datasets.GeneratorBasedBuilder):
60
+ """ParlamentParla."""
61
+
62
+ VERSION = datasets.Version("2.0.0")
63
+
64
+ BUILDER_CONFIGS = [
65
+ datasets.BuilderConfig(name="clean", version=VERSION, description="211 hours of clean quality segments."),
66
+ datasets.BuilderConfig(name="other", version=VERSION, description="400 hours of other quality segments."),
67
+ ]
68
+
69
+ def _info(self):
70
+ return datasets.DatasetInfo(
71
+ description=_DESCRIPTION,
72
+ features=datasets.Features(
73
+ {
74
+ "path": datasets.Value("string"),
75
+ "audio": datasets.features.Audio(),
76
+ "speaker_id": datasets.Value("int64"),
77
+ "sentence": datasets.Value("string"),
78
+ "gender": datasets.ClassLabel(names=["F", "M"]),
79
+ "duration": datasets.Value("float64"),
80
+ }
81
+ ),
82
+ supervised_keys=None,
83
+ homepage=_HOMEPAGE,
84
+ license=_LICENSE,
85
+ citation=_CITATION,
86
+ task_templates=[
87
+ AutomaticSpeechRecognition(audio_file_path_column="path", transcription_column="sentence")
88
+ ],
89
+ )
90
+
91
+ def _split_generators(self, dl_manager):
92
+ urls = {
93
+ split: {key: url.format(config=self.config.name, split=_SPLITS[split]) for key, url in _URLS.items()}
94
+ for split in _SPLITS
95
+ }
96
+ dl_dir = dl_manager.download(urls)
97
+ return [
98
+ datasets.SplitGenerator(
99
+ name=split,
100
+ gen_kwargs={
101
+ "index_path": dl_dir[split]["index"],
102
+ "audio_files": dl_manager.iter_archive(dl_dir[split]["audio"]),
103
+ },
104
+ )
105
+ for split in _SPLITS
106
+ ]
107
+
108
+ def _generate_examples(self, index_path, audio_files):
109
+ with open(index_path, encoding="utf-8") as index_file:
110
+ index = pd.read_csv(index_file, delimiter="\t", index_col="path").to_dict(orient="index")
111
+ # clean: 83568 = 79269 + 2155 + 2144 ; other: 146669 = 142813 + 1957 + 1899
112
+ for key, (path, file) in enumerate(audio_files):
113
+ if path.endswith(".wav"):
114
+ data = index.pop(path)
115
+ audio = {"path": path, "bytes": file.read()}
116
+ yield key, {"path": path, "audio": audio, **data}