# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # TODO: Address all TODOs and remove all explanatory comments """Build script for Polish ASR-BIGOS dataset""" import csv import json import os import datasets print("Running script") # TODO: Add BibTeX citation # Find for instance the citation on arxiv or on the dataset repo/website _CITATION = """\ @inproceedings{FedCSIS20231609, author={Michał Junczyk}, pages={585–590}, title={BIGOS - Benchmark Intended Grouping of Open Speech Corpora for Polish Automatic Speech Recognition}, booktitle={Proceedings of the 18th Conference on Computer Science and Intelligence Systems}, year={2023}, editor={Maria Ganzha and Leszek Maciaszek and Marcin Paprzycki and Dominik Ślęzak}, publisher={IEEE}, doi={10.15439/2023F1609}, url={http://dx.doi.org/10.15439/2023F1609}, volume={35}, series={Annals of Computer Science and Information Systems} } """ _DESCRIPTION = """\ BIGOS (Benchmark Intended Grouping of Open Speech) dataset goal is to simplify access to the openly available Polish speech corpora and enable systematic benchmarking of open and commercial Polish ASR systems. """ _HOMEPAGE = "https://huggingface.co/datasets/amu-cai/pl-asr-bigos-v2" _LICENSE = "CC-BY-SA-4.0" _BIGOS_SUBSETS = ["pjatk-clarin_mobile-15", "pjatk-clarin_studio-15", "fair-mls-20", "mailabs-corpus_librivox-19", "mozilla-common_voice_15-23", "pwr-azon_read-20", "pwr-azon_spont-20", "pwr-maleset-unk", "pwr-shortwords-unk", "pwr-viu-unk", "google-fleurs-22", "polyai-minds14-21"] _ALL_CONFIGS = [] for subset in _BIGOS_SUBSETS: _ALL_CONFIGS.append(subset) _ALL_CONFIGS.append("all") _BASE_PATH = "data/{subset}/" _DATA_URL = _BASE_PATH + "{split}.tar.gz" _META_URL = _BASE_PATH + "{split}.tsv" class BigosConfig(datasets.BuilderConfig): def __init__( self, name, description, citation, homepage ): super(BigosConfig, self).__init__( name=self.name, version=datasets.Version("2.0.0", ""), description=self.description, ) self.name = name self.description = description self.citation = citation self.homepage = homepage def _build_config(name): return BigosConfig( name=name, description=_DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE, ) class Bigos(datasets.GeneratorBasedBuilder): DEFAULT_WRITER_BATCH_SIZE = 2 #in case the issue persits, investigatae the following: #https://github.com/huggingface/datasets/issues/4057 BUILDER_CONFIGS = [_build_config(name) for name in _ALL_CONFIGS] def _info(self): task_templates = None features = datasets.Features( { "audioname": datasets.Value("string"), "split": datasets.Value("string"), "dataset": datasets.Value("string"), "speaker_id": datasets.Value("string"), "ref_orig": datasets.Value("string"), "audio": datasets.Audio(sampling_rate=16_000), "samplingrate_orig": datasets.Value("int32"), "sampling_rate": datasets.Value("int32"), "audiopath_bigos": datasets.Value("string"), "audiopath_local": datasets.Value("string"), #"ref_spoken": datasets.Value("string"), #"ref_written": datasets.Value("string"), #"hyp_whisper_cloud": datasets.Value("string"), #"hyp_google_default": datasets.Value("string"), #"hyp_azure_default": datasets.Value("string"), #"hyp_whisper_tiny": datasets.Value("string"), #"hyp_whisper_base": datasets.Value("string"), #"hyp_whisper_small": datasets.Value("string"), #"hyp_whisper_medium": datasets.Value("string"), #"hyp_whisper_large": datasets.Value("string") #"gender": datasets.ClassLabel(names=["male", "female", "other"]), #"speaker_id": datasets.Value("int32"), #"raw_transcription": datasets.Value("string"), } ) return datasets.DatasetInfo( description=self.config.description + "\n" + _DESCRIPTION, features=features, supervised_keys=("audio", "ref_orig"), homepage=self.config.homepage, citation=self.config.citation + "\n" + _CITATION, task_templates=task_templates, ) def _split_generators(self, dl_manager): splits = ["test", "train", "validation"] if self.config.name == "all": data_urls = {split: [_DATA_URL.format(subset=subset,split=split) for subset in _BIGOS_SUBSETS] for split in splits} meta_urls = {split: [_META_URL.format(subset=subset,split=split) for subset in _BIGOS_SUBSETS] for split in splits} else: data_urls = {split: [_DATA_URL.format(subset=self.config.name, split=split)] for split in splits} meta_urls = {split: [_META_URL.format(subset=self.config.name, split=split)] for split in splits} archive_paths = dl_manager.download(data_urls) local_extracted_archives = dl_manager.extract(archive_paths) if not dl_manager.is_streaming else {} archive_iters = {split: [dl_manager.iter_archive(path) for path in paths] for split, paths in archive_paths.items()} meta_paths = dl_manager.download(meta_urls) return [ datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "local_extracted_archives": local_extracted_archives.get("test", [None] * len(meta_paths.get("test"))), "archive_iters": archive_iters.get("test"), "text_paths": meta_paths.get("test") }, ), datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "local_extracted_archives": local_extracted_archives.get("train", [None] * len(meta_paths.get("train"))), "archive_iters": archive_iters.get("train"), "text_paths": meta_paths.get("train") }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "local_extracted_archives": local_extracted_archives.get("validation", [None] * len(meta_paths.get("validation"))), "archive_iters": archive_iters.get("validation"), "text_paths": meta_paths.get("validation") }, ), ] def _get_data(self, lines, subset_id): data = {} for line in lines: # parse TSV if isinstance(line, bytes): line = line.decode("utf-8") ( _id, split, dataset, speaker_id, sampling_rate_orig, sampling_rate, ref_orig, audio_path_bigos, ) = line.strip().split("\t") data[audio_path_bigos] = { "audioname": _id, "split": split, "dataset": dataset, "speaker_id": speaker_id, "samplingrate_orig": sampling_rate_orig, "sampling_rate": sampling_rate, "ref_orig": ref_orig, "audiopath_bigos": audio_path_bigos, #"age": int(age), } return data def _generate_examples(self, local_extracted_archives, archive_iters, text_paths): assert len(local_extracted_archives) == len(archive_iters) == len(text_paths) key = 0 print("Generating examples") if self.config.name == "all": subsets = _BIGOS_SUBSETS else: subsets = [self.config.name] for archive, text_path, local_extracted_path, subset_id in zip(archive_iters, text_paths, local_extracted_archives, subsets): with open(text_path, encoding="utf-8") as f: lines = f.readlines() data = self._get_data(lines, subset_id) for audio_path, audio_file in archive: #print("audio_path: ", audio_path) audio_filename = audio_path.split("/")[-1] #if audio_filename not in data.keys(): # continue #print("audio_filename: ", audio_filename) result = data[audio_filename] #print("result: ", result) extracted_audio_path = ( os.path.join(local_extracted_path, audio_filename) if local_extracted_path is not None else None ) #print("extracted_audio_path: ", extracted_audio_path) result["audiopath_local"] = extracted_audio_path result["audio"] = {"path": audio_path, "bytes": audio_file.read()} yield key, result key += 1