Datasets:
Commit
•
ab94660
1
Parent(s):
823ad47
reserve paths to locally extracted files
Browse files- ml_spoken_words.py +27 -8
ml_spoken_words.py
CHANGED
@@ -175,13 +175,16 @@ class MlSpokenWords(datasets.GeneratorBasedBuilder):
|
|
175 |
|
176 |
def _split_generators(self, dl_manager):
|
177 |
splits_archive_path = [dl_manager.download(_SPLITS_URL.format(lang=lang)) for lang in self.config.languages]
|
178 |
-
download_audio = partial(_download_audio_archives, format=self.config.format
|
|
|
179 |
|
180 |
return [
|
181 |
datasets.SplitGenerator(
|
182 |
name=datasets.Split.TRAIN,
|
183 |
gen_kwargs={
|
184 |
"audio_archives": [download_audio(split="train", lang=lang) for lang in self.config.languages],
|
|
|
|
|
185 |
"splits_archives": [dl_manager.iter_archive(path) for path in splits_archive_path],
|
186 |
"split": "train",
|
187 |
},
|
@@ -190,6 +193,8 @@ class MlSpokenWords(datasets.GeneratorBasedBuilder):
|
|
190 |
name=datasets.Split.VALIDATION,
|
191 |
gen_kwargs={
|
192 |
"audio_archives": [download_audio(split="dev", lang=lang) for lang in self.config.languages],
|
|
|
|
|
193 |
"splits_archives": [dl_manager.iter_archive(path) for path in splits_archive_path],
|
194 |
"split": "dev",
|
195 |
},
|
@@ -198,13 +203,15 @@ class MlSpokenWords(datasets.GeneratorBasedBuilder):
|
|
198 |
name=datasets.Split.TEST,
|
199 |
gen_kwargs={
|
200 |
"audio_archives": [download_audio(split="test", lang=lang) for lang in self.config.languages],
|
|
|
|
|
201 |
"splits_archives": [dl_manager.iter_archive(path) for path in splits_archive_path],
|
202 |
"split": "test",
|
203 |
},
|
204 |
),
|
205 |
]
|
206 |
|
207 |
-
def _generate_examples(self, audio_archives, splits_archives, split):
|
208 |
metadata = dict()
|
209 |
for lang_idx, lang in enumerate(self.config.languages):
|
210 |
for split_filename, split_file in splits_archives[lang_idx]:
|
@@ -221,18 +228,19 @@ class MlSpokenWords(datasets.GeneratorBasedBuilder):
|
|
221 |
"gender": gender if gender and gender != "NA" else "NAN", # some values are "NA"
|
222 |
}
|
223 |
|
224 |
-
for audio_archive in audio_archives[lang_idx]:
|
225 |
for audio_filename, audio_file in audio_archive:
|
226 |
audio_id, audio_ext = os.path.splitext(audio_filename)
|
|
|
227 |
yield audio_filename, {
|
228 |
-
"file":
|
229 |
"language": lang,
|
230 |
-
"audio": {"path":
|
231 |
**metadata[audio_id],
|
232 |
}
|
233 |
|
234 |
|
235 |
-
def
|
236 |
"""
|
237 |
All audio files are stored in several .tar.gz archives with names like 0.tar.gz, 1.tar.gz, ...
|
238 |
Number of archives stored in a separate .txt file (n_files.txt)
|
@@ -247,6 +255,17 @@ def _download_audio_archives(dl_manager, lang, format, split):
|
|
247 |
n_files = int(file.read().strip()) # the file contains a number of archives
|
248 |
|
249 |
archive_urls = [_AUDIO_URL.format(lang=lang, format=format, split=split, n=i) for i in range(n_files)]
|
250 |
-
archive_paths = dl_manager.download(archive_urls)
|
251 |
|
252 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
|
176 |
def _split_generators(self, dl_manager):
|
177 |
splits_archive_path = [dl_manager.download(_SPLITS_URL.format(lang=lang)) for lang in self.config.languages]
|
178 |
+
download_audio = partial(_download_audio_archives, dl_manager=dl_manager, format=self.config.format)
|
179 |
+
download_extract_audio = partial(_download_extract_audio_archives, dl_manager=dl_manager, format=self.config.format)
|
180 |
|
181 |
return [
|
182 |
datasets.SplitGenerator(
|
183 |
name=datasets.Split.TRAIN,
|
184 |
gen_kwargs={
|
185 |
"audio_archives": [download_audio(split="train", lang=lang) for lang in self.config.languages],
|
186 |
+
"local_audio_archives_paths": [download_extract_audio(split="train", lang=lang) for lang in
|
187 |
+
self.config.languages] if not dl_manager.is_streaming else None,
|
188 |
"splits_archives": [dl_manager.iter_archive(path) for path in splits_archive_path],
|
189 |
"split": "train",
|
190 |
},
|
|
|
193 |
name=datasets.Split.VALIDATION,
|
194 |
gen_kwargs={
|
195 |
"audio_archives": [download_audio(split="dev", lang=lang) for lang in self.config.languages],
|
196 |
+
"local_audio_archives_paths": [download_extract_audio(split="dev", lang=lang) for lang in
|
197 |
+
self.config.languages] if not dl_manager.is_streaming else None,
|
198 |
"splits_archives": [dl_manager.iter_archive(path) for path in splits_archive_path],
|
199 |
"split": "dev",
|
200 |
},
|
|
|
203 |
name=datasets.Split.TEST,
|
204 |
gen_kwargs={
|
205 |
"audio_archives": [download_audio(split="test", lang=lang) for lang in self.config.languages],
|
206 |
+
"local_audio_archives_paths": [download_extract_audio(split="test", lang=lang) for lang in
|
207 |
+
self.config.languages] if not dl_manager.is_streaming else None,
|
208 |
"splits_archives": [dl_manager.iter_archive(path) for path in splits_archive_path],
|
209 |
"split": "test",
|
210 |
},
|
211 |
),
|
212 |
]
|
213 |
|
214 |
+
def _generate_examples(self, audio_archives, local_audio_archives_paths, splits_archives, split):
|
215 |
metadata = dict()
|
216 |
for lang_idx, lang in enumerate(self.config.languages):
|
217 |
for split_filename, split_file in splits_archives[lang_idx]:
|
|
|
228 |
"gender": gender if gender and gender != "NA" else "NAN", # some values are "NA"
|
229 |
}
|
230 |
|
231 |
+
for archive_idx, audio_archive in enumerate(audio_archives[lang_idx]):
|
232 |
for audio_filename, audio_file in audio_archive:
|
233 |
audio_id, audio_ext = os.path.splitext(audio_filename)
|
234 |
+
path = os.path.join(local_audio_archives_paths[lang_idx][archive_idx], audio_filename) if local_audio_archives_paths else audio_filename
|
235 |
yield audio_filename, {
|
236 |
+
"file": path if local_audio_archives_paths else None,
|
237 |
"language": lang,
|
238 |
+
"audio": {"path": path, "bytes": audio_file.read()},
|
239 |
**metadata[audio_id],
|
240 |
}
|
241 |
|
242 |
|
243 |
+
def _download_audio_archives_paths(dl_manager, lang, format, split):
|
244 |
"""
|
245 |
All audio files are stored in several .tar.gz archives with names like 0.tar.gz, 1.tar.gz, ...
|
246 |
Number of archives stored in a separate .txt file (n_files.txt)
|
|
|
255 |
n_files = int(file.read().strip()) # the file contains a number of archives
|
256 |
|
257 |
archive_urls = [_AUDIO_URL.format(lang=lang, format=format, split=split, n=i) for i in range(n_files)]
|
|
|
258 |
|
259 |
+
return dl_manager.download(archive_urls)
|
260 |
+
|
261 |
+
|
262 |
+
# for default, non-streaming case
|
263 |
+
def _download_extract_audio_archives(dl_manager, lang, format, split):
|
264 |
+
archives_paths = _download_audio_archives_paths(dl_manager, lang, format, split)
|
265 |
+
return [dl_manager.extract(archive_path) for archive_path in archives_paths]
|
266 |
+
|
267 |
+
|
268 |
+
# for streaming case
|
269 |
+
def _download_audio_archives(dl_manager, lang, format, split):
|
270 |
+
archives_paths = _download_audio_archives_paths(dl_manager, lang, format, split)
|
271 |
+
return [dl_manager.iter_archive(archive_path) for archive_path in archives_paths]
|