back to previous version with bundleurltemplate ha hardcoded to 'bn'
Browse files- {data → bengali_ai_tsv}/train.tsv +0 -0
- CommonVoiceBangla.py → common_voice_bn.py +123 -136
- release_stats.py +1 -1
{data → bengali_ai_tsv}/train.tsv
RENAMED
File without changes
|
CommonVoiceBangla.py → common_voice_bn.py
RENAMED
@@ -1,60 +1,46 @@
|
|
1 |
-
# coding=utf-8
|
2 |
-
# Copyright 2022 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 |
-
""" Common Voice Dataset"""
|
16 |
-
|
17 |
-
|
18 |
import csv
|
19 |
import os
|
20 |
import urllib
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
22 |
import datasets
|
23 |
import requests
|
24 |
from datasets.utils.py_utils import size_str
|
25 |
from huggingface_hub import HfApi, HfFolder
|
26 |
|
27 |
-
from .languages import LANGUAGES
|
|
|
28 |
from .release_stats import STATS
|
29 |
|
30 |
-
_CITATION = """\
|
31 |
-
@inproceedings{commonvoice:2020,
|
32 |
-
author = {Ardila, R. and Branson, M. and Davis, K. and Henretty, M. and Kohler, M. and Meyer, J. and Morais, R. and Saunders, L. and Tyers, F. M. and Weber, G.},
|
33 |
-
title = {Common Voice: A Massively-Multilingual Speech Corpus},
|
34 |
-
booktitle = {Proceedings of the 12th Conference on Language Resources and Evaluation (LREC 2020)},
|
35 |
-
pages = {4211--4215},
|
36 |
-
year = 2020
|
37 |
-
}
|
38 |
-
"""
|
39 |
|
40 |
-
|
|
|
|
|
|
|
41 |
|
42 |
_LICENSE = "https://creativecommons.org/publicdomain/zero/1.0/"
|
43 |
|
44 |
_API_URL = "https://commonvoice.mozilla.org/api/v1"
|
45 |
|
46 |
|
|
|
|
|
|
|
47 |
class CommonVoiceConfig(datasets.BuilderConfig):
|
48 |
"""BuilderConfig for CommonVoice."""
|
49 |
|
50 |
def __init__(self, name, version, **kwargs):
|
51 |
-
self.language = kwargs.pop("language", None)
|
52 |
-
self.release_date = kwargs.pop("release_date", None)
|
53 |
-
self.num_clips = kwargs.pop("num_clips", None)
|
54 |
-
self.num_speakers = kwargs.pop("num_speakers", None)
|
55 |
-
self.validated_hr = kwargs.pop("validated_hr", None)
|
56 |
-
self.total_hr = kwargs.pop("total_hr", None)
|
57 |
-
self.size_bytes = kwargs.pop("size_bytes", None)
|
58 |
self.size_human = size_str(self.size_bytes)
|
59 |
description = (
|
60 |
f"Common Voice speech to text dataset in {self.language} released on {self.release_date}. "
|
@@ -71,31 +57,33 @@ class CommonVoiceConfig(datasets.BuilderConfig):
|
|
71 |
|
72 |
|
73 |
class CommonVoice(datasets.GeneratorBasedBuilder):
|
|
|
74 |
DEFAULT_CONFIG_NAME = "bn"
|
75 |
DEFAULT_WRITER_BATCH_SIZE = 1000
|
76 |
|
77 |
BUILDER_CONFIGS = [
|
78 |
CommonVoiceConfig(
|
79 |
-
name=lang,
|
80 |
-
version=STATS["version"],
|
81 |
-
language=LANGUAGES[lang],
|
82 |
-
release_date=STATS["date"],
|
83 |
-
num_clips=lang_stats["clips"],
|
84 |
-
num_speakers=lang_stats["users"],
|
85 |
-
validated_hr=float(lang_stats["validHrs"]),
|
86 |
-
total_hr=float(lang_stats["totalHrs"]),
|
87 |
-
size_bytes=int(lang_stats["size"]),
|
88 |
)
|
89 |
-
for lang, lang_stats in STATS["locales"].items()
|
90 |
]
|
91 |
|
92 |
def _info(self):
|
93 |
-
total_languages = len(STATS["locales"])
|
94 |
-
total_valid_hours = STATS["totalValidHrs"]
|
|
|
|
|
95 |
description = (
|
96 |
-
"Common Voice is
|
97 |
-
f"The dataset
|
98 |
-
f" in {total_languages} languages, but more voices and languages are always added."
|
99 |
)
|
100 |
features = datasets.Features(
|
101 |
{
|
@@ -108,7 +96,7 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
|
|
108 |
"age": datasets.Value("string"),
|
109 |
"gender": datasets.Value("string"),
|
110 |
"accent": datasets.Value("string"),
|
111 |
-
"locale":
|
112 |
"segment": datasets.Value("string"),
|
113 |
}
|
114 |
)
|
@@ -117,22 +105,26 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
|
|
117 |
description=description,
|
118 |
features=features,
|
119 |
supervised_keys=None,
|
120 |
-
homepage=_HOMEPAGE,
|
121 |
license=_LICENSE,
|
122 |
-
citation=_CITATION,
|
123 |
-
version=self.config.version,
|
124 |
-
#
|
125 |
-
#
|
126 |
-
#
|
127 |
)
|
128 |
|
|
|
129 |
def _get_bundle_url(self, locale, url_template):
|
130 |
# path = encodeURIComponent(path)
|
131 |
-
path = url_template.replace("{locale}", locale)
|
|
|
132 |
path = urllib.parse.quote(path.encode("utf-8"), safe="~()*!.'")
|
133 |
# use_cdn = self.config.size_bytes < 20 * 1024 * 1024 * 1024
|
134 |
# response = requests.get(f"{_API_URL}/bucket/dataset/{path}/{use_cdn}", timeout=10.0).json()
|
135 |
-
response = requests.get(
|
|
|
|
|
136 |
return response["url"]
|
137 |
|
138 |
def _log_download(self, locale, bundle_version, auth_token):
|
@@ -156,8 +148,12 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
|
|
156 |
dl_manager.download_config.ignore_url_params = True
|
157 |
|
158 |
self._log_download(self.config.name, bundle_version, hf_auth_token)
|
159 |
-
archive_path = dl_manager.download(
|
160 |
-
|
|
|
|
|
|
|
|
|
161 |
|
162 |
if self.config.version < datasets.Version("5.0.0"):
|
163 |
path_to_data = ""
|
@@ -165,16 +161,21 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
|
|
165 |
path_to_data = "/".join([bundle_version, self.config.name])
|
166 |
path_to_clips = "/".join([path_to_data, "clips"]) if path_to_data else "clips"
|
167 |
|
168 |
-
|
|
|
|
|
169 |
return [
|
170 |
datasets.SplitGenerator(
|
171 |
name=datasets.Split.TRAIN,
|
172 |
gen_kwargs={
|
173 |
"local_extracted_archive": local_extracted_archive,
|
174 |
"archive_iterator": dl_manager.iter_archive(archive_path),
|
175 |
-
"metadata_filepath": "/
|
|
|
|
|
|
|
|
|
176 |
"path_to_clips": path_to_clips,
|
177 |
-
"mode":"train",
|
178 |
},
|
179 |
),
|
180 |
datasets.SplitGenerator(
|
@@ -182,9 +183,12 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
|
|
182 |
gen_kwargs={
|
183 |
"local_extracted_archive": local_extracted_archive,
|
184 |
"archive_iterator": dl_manager.iter_archive(archive_path),
|
185 |
-
"metadata_filepath": "/".join([path_to_data, "test.tsv"])
|
|
|
|
|
|
|
|
|
186 |
"path_to_clips": path_to_clips,
|
187 |
-
"mode":"test",
|
188 |
},
|
189 |
),
|
190 |
datasets.SplitGenerator(
|
@@ -192,88 +196,71 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
|
|
192 |
gen_kwargs={
|
193 |
"local_extracted_archive": local_extracted_archive,
|
194 |
"archive_iterator": dl_manager.iter_archive(archive_path),
|
195 |
-
"metadata_filepath": "/".join([path_to_data, "dev.tsv"])
|
|
|
|
|
|
|
|
|
196 |
"path_to_clips": path_to_clips,
|
197 |
-
"mode":"dev",
|
198 |
},
|
199 |
),
|
200 |
]
|
201 |
|
|
|
|
|
202 |
def _generate_examples(
|
203 |
self,
|
204 |
local_extracted_archive,
|
205 |
archive_iterator,
|
206 |
metadata_filepath,
|
207 |
path_to_clips,
|
208 |
-
mode
|
209 |
):
|
210 |
"""Yields examples."""
|
211 |
data_fields = list(self._info().features.keys())
|
212 |
metadata = {}
|
213 |
metadata_found = False
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
for
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
row["accent"] = row["accents"]
|
260 |
-
del row["accents"]
|
261 |
-
# if data is incomplete, fill with empty values
|
262 |
-
for field in data_fields:
|
263 |
-
if field not in row:
|
264 |
-
row[field] = ""
|
265 |
-
metadata[row["path"]] = row
|
266 |
-
for path, f in archive_iterator:
|
267 |
-
if path.startswith(path_to_clips):
|
268 |
-
assert metadata_found, "Found audio clips before the metadata TSV file."
|
269 |
-
if not metadata:
|
270 |
-
break
|
271 |
-
if path in metadata:
|
272 |
-
result = metadata[path]
|
273 |
-
# set the audio feature and the path to the extracted file
|
274 |
-
path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path
|
275 |
-
result["audio"] = {"path": path, "bytes": f.read()}
|
276 |
-
# set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
|
277 |
-
result["path"] = path if local_extracted_archive else None
|
278 |
-
|
279 |
-
yield path, result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import csv
|
2 |
import os
|
3 |
import urllib
|
4 |
+
|
5 |
+
|
6 |
+
import datasets
|
7 |
+
from datasets.utils.py_utils import size_str
|
8 |
+
|
9 |
+
|
10 |
import datasets
|
11 |
import requests
|
12 |
from datasets.utils.py_utils import size_str
|
13 |
from huggingface_hub import HfApi, HfFolder
|
14 |
|
15 |
+
# from .languages import LANGUAGES
|
16 |
+
#Used to get tar.gz file from mozilla website
|
17 |
from .release_stats import STATS
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
|
21 |
+
#Hard Links
|
22 |
+
|
23 |
+
_HOMEPAGE = "https://commonvoice.mozilla.org/en/datasets"
|
24 |
|
25 |
_LICENSE = "https://creativecommons.org/publicdomain/zero/1.0/"
|
26 |
|
27 |
_API_URL = "https://commonvoice.mozilla.org/api/v1"
|
28 |
|
29 |
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
class CommonVoiceConfig(datasets.BuilderConfig):
|
34 |
"""BuilderConfig for CommonVoice."""
|
35 |
|
36 |
def __init__(self, name, version, **kwargs):
|
37 |
+
self.language = "bn" # kwargs.pop("language", None)
|
38 |
+
self.release_date = "2022-04-27" # kwargs.pop("release_date", None)
|
39 |
+
self.num_clips = 231120 # kwargs.pop("num_clips", None)
|
40 |
+
self.num_speakers = 19863 # kwargs.pop("num_speakers", None)
|
41 |
+
self.validated_hr = 56.61 # kwargs.pop("validated_hr", None)
|
42 |
+
self.total_hr = 399.47 # kwargs.pop("total_hr", None)
|
43 |
+
self.size_bytes = 8262390506 # kwargs.pop("size_bytes", None)
|
44 |
self.size_human = size_str(self.size_bytes)
|
45 |
description = (
|
46 |
f"Common Voice speech to text dataset in {self.language} released on {self.release_date}. "
|
|
|
57 |
|
58 |
|
59 |
class CommonVoice(datasets.GeneratorBasedBuilder):
|
60 |
+
#DEFAULT_CONFIG_NAME = "en"
|
61 |
DEFAULT_CONFIG_NAME = "bn"
|
62 |
DEFAULT_WRITER_BATCH_SIZE = 1000
|
63 |
|
64 |
BUILDER_CONFIGS = [
|
65 |
CommonVoiceConfig(
|
66 |
+
name="bn"#lang,
|
67 |
+
version= '9.0.0' #STATS["version"],
|
68 |
+
language= "Bengali" #LANGUAGES[lang],
|
69 |
+
release_date= "2022-04-27" #STATS["date"],
|
70 |
+
num_clips= 231120 #lang_stats["clips"],
|
71 |
+
num_speakers= 19863 #lang_stats["users"],
|
72 |
+
validated_hr= float(56.61) #float(lang_stats["validHrs"]),
|
73 |
+
total_hr= float(399.47) #float(lang_stats["totalHrs"]),
|
74 |
+
size_bytes= int(8262390506) #int(lang_stats["size"]),
|
75 |
)
|
76 |
+
#for lang, lang_stats in STATS["locales"].items()
|
77 |
]
|
78 |
|
79 |
def _info(self):
|
80 |
+
# total_languages = len(STATS["locales"])
|
81 |
+
# total_valid_hours = STATS["totalValidHrs"]
|
82 |
+
total_languages = 1 #len(STATS["locales"])
|
83 |
+
total_valid_hours = float(399.47) #STATS["totalValidHrs"]
|
84 |
description = (
|
85 |
+
"Common Voice Bangla is bengali AI's initiative to help teach machines how real people speak in Bangla. "
|
86 |
+
f"The dataset is for initial training of a general speech recognition model for Bangla."
|
|
|
87 |
)
|
88 |
features = datasets.Features(
|
89 |
{
|
|
|
96 |
"age": datasets.Value("string"),
|
97 |
"gender": datasets.Value("string"),
|
98 |
"accent": datasets.Value("string"),
|
99 |
+
"locale": 'bn',
|
100 |
"segment": datasets.Value("string"),
|
101 |
}
|
102 |
)
|
|
|
105 |
description=description,
|
106 |
features=features,
|
107 |
supervised_keys=None,
|
108 |
+
# homepage=_HOMEPAGE,
|
109 |
license=_LICENSE,
|
110 |
+
# citation=_CITATION,
|
111 |
+
version=self.config.version,
|
112 |
+
#task_templates=[
|
113 |
+
# AutomaticSpeechRecognition(audio_file_path_column="path", transcription_column="sentence")
|
114 |
+
#],
|
115 |
)
|
116 |
|
117 |
+
|
118 |
def _get_bundle_url(self, locale, url_template):
|
119 |
# path = encodeURIComponent(path)
|
120 |
+
# path = url_template.replace("{locale}", locale)
|
121 |
+
path = url_template
|
122 |
path = urllib.parse.quote(path.encode("utf-8"), safe="~()*!.'")
|
123 |
# use_cdn = self.config.size_bytes < 20 * 1024 * 1024 * 1024
|
124 |
# response = requests.get(f"{_API_URL}/bucket/dataset/{path}/{use_cdn}", timeout=10.0).json()
|
125 |
+
response = requests.get(
|
126 |
+
f"{_API_URL}/bucket/dataset/{path}", timeout=10.0
|
127 |
+
).json()
|
128 |
return response["url"]
|
129 |
|
130 |
def _log_download(self, locale, bundle_version, auth_token):
|
|
|
148 |
dl_manager.download_config.ignore_url_params = True
|
149 |
|
150 |
self._log_download(self.config.name, bundle_version, hf_auth_token)
|
151 |
+
archive_path = dl_manager.download(
|
152 |
+
self._get_bundle_url(self.config.name, bundle_url_template)
|
153 |
+
)
|
154 |
+
local_extracted_archive = (
|
155 |
+
dl_manager.extract(archive_path) if not dl_manager.is_streaming else None
|
156 |
+
)
|
157 |
|
158 |
if self.config.version < datasets.Version("5.0.0"):
|
159 |
path_to_data = ""
|
|
|
161 |
path_to_data = "/".join([bundle_version, self.config.name])
|
162 |
path_to_clips = "/".join([path_to_data, "clips"]) if path_to_data else "clips"
|
163 |
|
164 |
+
#we provide our custom csvs with the huggingface repo so,
|
165 |
+
path_to_tsvs = "/" + "bengali_ai_tsv" + "/"
|
166 |
+
|
167 |
return [
|
168 |
datasets.SplitGenerator(
|
169 |
name=datasets.Split.TRAIN,
|
170 |
gen_kwargs={
|
171 |
"local_extracted_archive": local_extracted_archive,
|
172 |
"archive_iterator": dl_manager.iter_archive(archive_path),
|
173 |
+
#"metadata_filepath": "/".join([path_to_data, "train.tsv"])
|
174 |
+
# if path_to_data
|
175 |
+
# else "train.tsv",
|
176 |
+
#custom train.tsv
|
177 |
+
"metadata_filepath": "/".join([path_to_tsvs, "train.tsv"]),
|
178 |
"path_to_clips": path_to_clips,
|
|
|
179 |
},
|
180 |
),
|
181 |
datasets.SplitGenerator(
|
|
|
183 |
gen_kwargs={
|
184 |
"local_extracted_archive": local_extracted_archive,
|
185 |
"archive_iterator": dl_manager.iter_archive(archive_path),
|
186 |
+
#"metadata_filepath": "/".join([path_to_data, "test.tsv"])
|
187 |
+
# if path_to_data
|
188 |
+
# else "test.tsv",
|
189 |
+
#custom test.tsv
|
190 |
+
"metadata_filepath": "/".join([path_to_tsvs, "test.tsv"]),
|
191 |
"path_to_clips": path_to_clips,
|
|
|
192 |
},
|
193 |
),
|
194 |
datasets.SplitGenerator(
|
|
|
196 |
gen_kwargs={
|
197 |
"local_extracted_archive": local_extracted_archive,
|
198 |
"archive_iterator": dl_manager.iter_archive(archive_path),
|
199 |
+
# "metadata_filepath": "/".join([path_to_data, "dev.tsv"])
|
200 |
+
# if path_to_data
|
201 |
+
# else "dev.tsv",
|
202 |
+
#custom test.tsv
|
203 |
+
"metadata_filepath": "/".join([path_to_tsvs, "dev.tsv"]),
|
204 |
"path_to_clips": path_to_clips,
|
|
|
205 |
},
|
206 |
),
|
207 |
]
|
208 |
|
209 |
+
|
210 |
+
|
211 |
def _generate_examples(
|
212 |
self,
|
213 |
local_extracted_archive,
|
214 |
archive_iterator,
|
215 |
metadata_filepath,
|
216 |
path_to_clips,
|
|
|
217 |
):
|
218 |
"""Yields examples."""
|
219 |
data_fields = list(self._info().features.keys())
|
220 |
metadata = {}
|
221 |
metadata_found = False
|
222 |
+
for path, f in archive_iterator:
|
223 |
+
if path == metadata_filepath:
|
224 |
+
metadata_found = True
|
225 |
+
lines = (line.decode("utf-8") for line in f)
|
226 |
+
reader = csv.DictReader(lines, delimiter="\t", quoting=csv.QUOTE_NONE)
|
227 |
+
for row in reader:
|
228 |
+
# set absolute path for mp3 audio file
|
229 |
+
if not row["path"].endswith(".mp3"):
|
230 |
+
row["path"] += ".mp3"
|
231 |
+
row["path"] = os.path.join(path_to_clips, row["path"])
|
232 |
+
# accent -> accents in CV 8.0
|
233 |
+
if "accents" in row:
|
234 |
+
row["accent"] = row["accents"]
|
235 |
+
del row["accents"]
|
236 |
+
# if data is incomplete, fill with empty values
|
237 |
+
for field in data_fields:
|
238 |
+
if field not in row:
|
239 |
+
row[field] = ""
|
240 |
+
metadata[row["path"]] = row
|
241 |
+
elif path.startswith(path_to_clips):
|
242 |
+
assert metadata_found, "Found audio clips before the metadata TSV file."
|
243 |
+
if not metadata:
|
244 |
+
break
|
245 |
+
if path in metadata:
|
246 |
+
result = metadata[path]
|
247 |
+
# set the audio feature and the path to the extracted file
|
248 |
+
path = (
|
249 |
+
os.path.join(local_extracted_archive, path)
|
250 |
+
if local_extracted_archive
|
251 |
+
else path
|
252 |
+
)
|
253 |
+
result["audio"] = {"path": path, "bytes": f.read()}
|
254 |
+
# set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
|
255 |
+
result["path"] = path if local_extracted_archive else None
|
256 |
+
|
257 |
+
yield path, result
|
258 |
+
|
259 |
+
|
260 |
+
|
261 |
+
# 'bn': {'duration': 1438112808, 'reportedSentences': 693, 'buckets': {'dev': 7748, 'invalidated': 5844, 'other': 192522,
|
262 |
+
# 'reported': 717, 'test': 7748, 'train': 14503, 'validated': 32754}, 'clips': 231120, 'splits': {'accent': {'': 1},
|
263 |
+
# 'age': {'thirties': 0.02, 'twenties': 0.22, '': 0.72, 'teens': 0.04, 'fourties': 0},
|
264 |
+
# 'gender': {'male': 0.24, '': 0.72, 'female': 0.04, 'other': 0}}, 'users': 19863, 'size': 8262390506,
|
265 |
+
# 'checksum': '599a5f7c9e55a297928da390345a19180b279a1f013081e7255a657fc99f98d5', 'avgDurationSecs': 6.222,
|
266 |
+
# 'validDurationSecs': 203807.316, 'totalHrs': 399.47, 'validHrs': 56.61},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
release_stats.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
STATS = {
|
2 |
-
"bundleURLTemplate":
|
3 |
"date": "2022-04-27",
|
4 |
"name": "Common Voice Corpus 9.0",
|
5 |
"multilingual": True,
|
|
|
1 |
STATS = {
|
2 |
+
"bundleURLTemplate": "cv-corpus-9.0-2022-04-27/cv-corpus-9.0-2022-04-27-bn.tar.gz",
|
3 |
"date": "2022-04-27",
|
4 |
"name": "Common Voice Corpus 9.0",
|
5 |
"multilingual": True,
|