Commit
•
693cf23
1
Parent(s):
575441a
up
Browse files- tedlium.py +28 -2
tedlium.py
CHANGED
@@ -31,6 +31,9 @@ _DL_URL = "https://huggingface.co/datasets/LIUM/tedlium/resolve/main/"
|
|
31 |
|
32 |
_LICENSE = "licensed under Creative Commons BY-NC-ND 3.0 (http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en)"
|
33 |
|
|
|
|
|
|
|
34 |
|
35 |
class TedliumReleaseConfig(datasets.BuilderConfig):
|
36 |
"""BuilderConfig for a release of the TED-LIUM dataset."""
|
@@ -232,6 +235,7 @@ class TedLium(datasets.GeneratorBasedBuilder):
|
|
232 |
"gender": datasets.features.ClassLabel(names=["unknown", "female", "male"]),
|
233 |
"file": datasets.Value("string"),
|
234 |
"id": datasets.Value("string"),
|
|
|
235 |
}
|
236 |
)
|
237 |
return datasets.DatasetInfo(
|
@@ -245,20 +249,35 @@ class TedLium(datasets.GeneratorBasedBuilder):
|
|
245 |
)
|
246 |
|
247 |
def _split_generators(self, dl_manager):
|
|
|
|
|
|
|
248 |
archive_path = dl_manager.download(self.config.download_urls)
|
249 |
# (Optional) In non-streaming mode, we can extract the archive locally to have actual local audio files:
|
250 |
local_extracted_archive = dl_manager.extract(archive_path) if not dl_manager.is_streaming else {}
|
|
|
|
|
|
|
|
|
251 |
splits = []
|
252 |
for split, path in self.config.split_paths:
|
253 |
kwargs = {
|
254 |
"filepath": [dl_manager.iter_archive(sharded_path) for sharded_path in archive_path[split]],
|
255 |
"local_extracted_archive": local_extracted_archive.get(split),
|
256 |
"split_path": path,
|
|
|
257 |
}
|
258 |
splits.append(datasets.SplitGenerator(name=split, gen_kwargs=kwargs))
|
259 |
return splits
|
260 |
|
261 |
-
def _generate_examples(self, filepath, local_extracted_archive, split_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
"""Generate examples from a TED-LIUM stm file."""
|
263 |
if local_extracted_archive:
|
264 |
for local_archive in local_extracted_archive:
|
@@ -289,8 +308,10 @@ class TedLium(datasets.GeneratorBasedBuilder):
|
|
289 |
"gender": _parse_gender(label),
|
290 |
"file": audio_file,
|
291 |
"id": key,
|
|
|
292 |
}
|
293 |
yield key, example
|
|
|
294 |
|
295 |
else:
|
296 |
audio_data = {}
|
@@ -337,14 +358,19 @@ class TedLium(datasets.GeneratorBasedBuilder):
|
|
337 |
)
|
338 |
audio = {"path": transcript["file"], "array": samples, "sampling_rate": sampling_rate}
|
339 |
key = transcript["id"]
|
|
|
|
|
340 |
yield key, {
|
341 |
"audio": audio,
|
342 |
-
"text":
|
343 |
"speaker_id": transcript["speaker_id"],
|
344 |
"gender": transcript["gender"],
|
345 |
"file": transcript["file"],
|
346 |
"id": transcript["id"],
|
|
|
347 |
}
|
|
|
|
|
348 |
audio_data = {}
|
349 |
transcripts = defaultdict(list)
|
350 |
|
|
|
31 |
|
32 |
_LICENSE = "licensed under Creative Commons BY-NC-ND 3.0 (http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en)"
|
33 |
|
34 |
+
_WHISPER_TRANSCRIPT_URL = "https://huggingface.co/datasets/distil-whisper/tedlium/resolve/main/transcription_data/greedy_search/"
|
35 |
+
_WHISPER_TRANSCRIPT_URLs = _WHISPER_TRANSCRIPT_URL + "/{split}-transcription.txt"
|
36 |
+
|
37 |
|
38 |
class TedliumReleaseConfig(datasets.BuilderConfig):
|
39 |
"""BuilderConfig for a release of the TED-LIUM dataset."""
|
|
|
235 |
"gender": datasets.features.ClassLabel(names=["unknown", "female", "male"]),
|
236 |
"file": datasets.Value("string"),
|
237 |
"id": datasets.Value("string"),
|
238 |
+
"whisper_transcript": datasets.Value("string"),
|
239 |
}
|
240 |
)
|
241 |
return datasets.DatasetInfo(
|
|
|
249 |
)
|
250 |
|
251 |
def _split_generators(self, dl_manager):
|
252 |
+
if self.config.name != "release3":
|
253 |
+
raise ValueError("This dataset is only compatible with the `release3` config.")
|
254 |
+
|
255 |
archive_path = dl_manager.download(self.config.download_urls)
|
256 |
# (Optional) In non-streaming mode, we can extract the archive locally to have actual local audio files:
|
257 |
local_extracted_archive = dl_manager.extract(archive_path) if not dl_manager.is_streaming else {}
|
258 |
+
|
259 |
+
transcription_urls = {split: _WHISPER_TRANSCRIPT_URLs.format(split=split) for split in ["train", "validation", "test"]}
|
260 |
+
transcript_archive_path = dl_manager.download(transcription_urls)
|
261 |
+
|
262 |
splits = []
|
263 |
for split, path in self.config.split_paths:
|
264 |
kwargs = {
|
265 |
"filepath": [dl_manager.iter_archive(sharded_path) for sharded_path in archive_path[split]],
|
266 |
"local_extracted_archive": local_extracted_archive.get(split),
|
267 |
"split_path": path,
|
268 |
+
"whisper_transcript": transcript_archive_path[split if split != "dev" else "validation"]
|
269 |
}
|
270 |
splits.append(datasets.SplitGenerator(name=split, gen_kwargs=kwargs))
|
271 |
return splits
|
272 |
|
273 |
+
def _generate_examples(self, filepath, local_extracted_archive, split_path, whisper_transcript):
|
274 |
+
whisper_transcripts = []
|
275 |
+
|
276 |
+
with open(whisper_transcript, encoding="utf-8") as f:
|
277 |
+
for row in f:
|
278 |
+
whisper_transcripts.append(row.rstrip("\n"))
|
279 |
+
idx = 0
|
280 |
+
|
281 |
"""Generate examples from a TED-LIUM stm file."""
|
282 |
if local_extracted_archive:
|
283 |
for local_archive in local_extracted_archive:
|
|
|
308 |
"gender": _parse_gender(label),
|
309 |
"file": audio_file,
|
310 |
"id": key,
|
311 |
+
"whisper_transcript": whisper_transcripts[idx]
|
312 |
}
|
313 |
yield key, example
|
314 |
+
idx += 1
|
315 |
|
316 |
else:
|
317 |
audio_data = {}
|
|
|
358 |
)
|
359 |
audio = {"path": transcript["file"], "array": samples, "sampling_rate": sampling_rate}
|
360 |
key = transcript["id"]
|
361 |
+
transcript_text = transcript["text"]
|
362 |
+
whisper_transcription = whisper_transcripts[idx] if transcript_text != "ignore_time_segment_in_scoring" else "ignore_time_segment_in_scoring"
|
363 |
yield key, {
|
364 |
"audio": audio,
|
365 |
+
"text": transcript_text,
|
366 |
"speaker_id": transcript["speaker_id"],
|
367 |
"gender": transcript["gender"],
|
368 |
"file": transcript["file"],
|
369 |
"id": transcript["id"],
|
370 |
+
"whisper_transcript": whisper_transcription
|
371 |
}
|
372 |
+
idx += 1
|
373 |
+
|
374 |
audio_data = {}
|
375 |
transcripts = defaultdict(list)
|
376 |
|