add script
Browse files- clarinpl_sejmsenat.py +127 -0
clarinpl_sejmsenat.py
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2021 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
3 |
+
# Copyright 2021 Jim O'Regan
|
4 |
+
#
|
5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
+
# you may not use this file except in compliance with the License.
|
7 |
+
# You may obtain a copy of the License at
|
8 |
+
#
|
9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
#
|
11 |
+
# Unless required by applicable law or agreed to in writing, software
|
12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
+
# See the License for the specific language governing permissions and
|
15 |
+
# limitations under the License.
|
16 |
+
|
17 |
+
# Lint as: python3
|
18 |
+
"""ClarinPL Sejm/Senat automatic speech recognition dataset."""
|
19 |
+
|
20 |
+
import os
|
21 |
+
|
22 |
+
import datasets
|
23 |
+
|
24 |
+
|
25 |
+
_CITATION = """\
|
26 |
+
@article{marasek2014system,
|
27 |
+
title={System for automatic transcription of sessions of the {P}olish {S}enate},
|
28 |
+
author={Marasek, Krzysztof and Kor{\v{z}}inek, Danijel and Brocki, {\L}ukasz},
|
29 |
+
journal={Archives of Acoustics},
|
30 |
+
volume={39},
|
31 |
+
number={4},
|
32 |
+
pages={501--509},
|
33 |
+
year={2014}
|
34 |
+
}
|
35 |
+
"""
|
36 |
+
|
37 |
+
_DESCRIPTION = """\
|
38 |
+
A collection of 97 hours of parliamentary speeches published on the ClarinPL website
|
39 |
+
|
40 |
+
Note that in order to limit the required storage for preparing this dataset, the audio
|
41 |
+
is stored in the .wav format and is not converted to a float32 array. To convert the audio
|
42 |
+
file to a float32 array, please make use of the `.map()` function as follows:
|
43 |
+
|
44 |
+
```python
|
45 |
+
import soundfile as sf
|
46 |
+
|
47 |
+
def map_to_array(batch):
|
48 |
+
speech_array, _ = sf.read(batch["file"])
|
49 |
+
batch["speech"] = speech_array
|
50 |
+
return batch
|
51 |
+
|
52 |
+
dataset = dataset.map(map_to_array, remove_columns=["file"])
|
53 |
+
```
|
54 |
+
"""
|
55 |
+
|
56 |
+
_URL = "https://mowa.clarin-pl.eu/"
|
57 |
+
_DS_URL = "http://mowa.clarin-pl.eu/korpusy/parlament/parlament.tar.gz"
|
58 |
+
|
59 |
+
class ClarinPLSejmSenatASRConfig(datasets.BuilderConfig):
|
60 |
+
"""BuilderConfig for ClarinPLSejmSenatASR."""
|
61 |
+
|
62 |
+
def __init__(self, **kwargs):
|
63 |
+
"""
|
64 |
+
Args:
|
65 |
+
data_dir: `string`, the path to the folder containing the files in the
|
66 |
+
downloaded .tar
|
67 |
+
citation: `string`, citation for the data set
|
68 |
+
url: `string`, url for information about the data set
|
69 |
+
**kwargs: keyword arguments forwarded to super.
|
70 |
+
"""
|
71 |
+
super(ClarinPLSejmSenatASRConfig, self).__init__(version=datasets.Version("2.1.0", ""), **kwargs)
|
72 |
+
|
73 |
+
|
74 |
+
class ClarinPLSejmSenat(datasets.GeneratorBasedBuilder):
|
75 |
+
"""ClarinPL Sejm/Senat dataset."""
|
76 |
+
|
77 |
+
BUILDER_CONFIGS = [
|
78 |
+
ClarinPLSejmSenatASRConfig(name="clean", description="'Clean' speech."),
|
79 |
+
]
|
80 |
+
|
81 |
+
def _info(self):
|
82 |
+
return datasets.DatasetInfo(
|
83 |
+
description=_DESCRIPTION,
|
84 |
+
features=datasets.Features(
|
85 |
+
{
|
86 |
+
"file": datasets.Value("string"),
|
87 |
+
"text": datasets.Value("string"),
|
88 |
+
"speaker_id": datasets.Value("string"),
|
89 |
+
"id": datasets.Value("string"),
|
90 |
+
}
|
91 |
+
),
|
92 |
+
supervised_keys=("file", "text"),
|
93 |
+
homepage=_URL,
|
94 |
+
citation=_CITATION,
|
95 |
+
)
|
96 |
+
|
97 |
+
def _split_generators(self, dl_manager):
|
98 |
+
archive_path = dl_manager.download_and_extract(_DS_URL)
|
99 |
+
archive_path = os.path.join(archive_path, "SejmSenat")
|
100 |
+
audio_path = os.path.join(archive_path, "audio")
|
101 |
+
return [
|
102 |
+
datasets.SplitGenerator(name="train", gen_kwargs={
|
103 |
+
"archive_path": os.path.join(archive_path, "train"),
|
104 |
+
"audio_path": audio_path
|
105 |
+
}),
|
106 |
+
datasets.SplitGenerator(name="test", gen_kwargs={
|
107 |
+
"archive_path": os.path.join(archive_path, "test"),
|
108 |
+
"audio_path": audio_path
|
109 |
+
}),
|
110 |
+
]
|
111 |
+
|
112 |
+
def _generate_examples(self, archive_path, audio_path):
|
113 |
+
"""Generate examples from a ClarinPL Sejm/Senat archive_path."""
|
114 |
+
with open(os.path.join(archive_path, "text"), "r", encoding="utf-8") as f:
|
115 |
+
for line in f:
|
116 |
+
line = line.strip()
|
117 |
+
key, transcript = line.split(" ", 1)
|
118 |
+
parts = key.split('-')
|
119 |
+
dir = '-'.join(parts[0:2])
|
120 |
+
audio_file = f'{parts[2]}.wav'
|
121 |
+
example = {
|
122 |
+
"id": key,
|
123 |
+
"speaker_id": parts[0],
|
124 |
+
"file": os.path.join(audio_path, dir, audio_file),
|
125 |
+
"text": transcript,
|
126 |
+
}
|
127 |
+
yield key, example
|