# coding=utf-8 # Copyright 2023 The HuggingFace Datasets Authors. # # Licensed under the Creative Commons version 4.0 and Mozilla Public License version 2.0, # (the "Licenses"); you may not use this file except in compliance with the Licenses. # You may obtain a copies of the Licenses at # # https://creativecommons.org/licenses/by/4.0/ # and https://www.mozilla.org/en-US/MPL/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 Licenses for the specific language governing permissions and # limitations under the Licenses. # Lint as: python3 import csv import os import json import datasets from datasets.utils.py_utils import size_str from tqdm import tqdm _CITATION = """\ @inproceedings{pudo23_interspeech, author={Mikołaj Pudo and Mateusz Wosik and Adam Cieślak and Justyna Krzywdziak and Bożena Łukasiak and Artur Janicki}, title={{MOCKS} 1.0: Multilingual Open Custom Keyword Spotting Testset}, year={2023}, booktitle={Proc. Interspeech 2023}, } """ _DESCRIPTION = """\ Multilingual Open Custom Keyword Spotting Testset (MOCKS) is a comprehensive audio testset for evaluation and benchmarking Open-Vocabulary Keyword Spotting (OV-KWS) models. """ _BASE_URL = "https://huggingface.co/datasets/voiceintelligenceresearch/MOCKS/tree/main" _DL_URL = "https://huggingface.co/datasets/voiceintelligenceresearch/MOCKS/blob/main/" _TR_URL = "https://huggingface.co/datasets/voiceintelligenceresearch/MOCKS/raw/main/" _DL_URLS = { "de.MCV": { "offline": _DL_URL + "de/MCV/test/offline/data.tar.gz", "online": _DL_URL + "de/MCV/test/online/data.tar.gz", "offline_transcription" : _TR_URL + "de/MCV/test/data_offline_transcription.tsv", "online_transcription" : _TR_URL + "de/MCV/test/data_online_transcription.tsv", }, "en.LS-clean": { "offline": _DL_URL + "en/LS-clean/test/offline/data.tar.gz", "online": _DL_URL + "en/LS-clean/test/online/data.tar.gz", "offline_transcription" : _TR_URL + "en/LS-clean/test/data_offline_transcription.tsv", "online_transcription" : _TR_URL + "en/LS-clean/test/data_online_transcription.tsv", }, "en.LS-other": { "offline": _DL_URL + "en/LS-other/test/offline/data.tar.gz", "online": _DL_URL + "en/LS-other/test/online/data.tar.gz", "offline_transcription" : _TR_URL + "en/LS-other/test/data_offline_transcription.tsv", "online_transcription" : _TR_URL + "en/LS-other/test/data_online_transcription.tsv", }, "en.MCV": { "offline": _DL_URL + "en/MCV/test/offline/data.tar.gz", "online": _DL_URL + "en/MCV/test/online/data.tar.gz", "offline_transcription" : _TR_URL + "en/MCV/test/data_offline_transcription.tsv", "online_transcription" : _TR_URL + "en/MCV/test/data_online_transcription.tsv", }, "es.MCV": { "offline": _DL_URL + "es/MCV/test/offline/data.tar.gz", "online": _DL_URL + "es/MCV/test/online/data.tar.gz", "offline_transcription" : _TR_URL + "es/MCV/test/data_offline_transcription.tsv", "online_transcription" : _TR_URL + "es/MCV/test/data_online_transcription.tsv", }, "fr.MCV": { "offline": _DL_URL + "fr/MCV/test/offline/data.tar.gz", "online": _DL_URL + "fr/MCV/test/online/data.tar.gz", "offline_transcription" : _TR_URL + "fr/MCV/test/data_offline_transcription.tsv", "online_transcription" : _TR_URL + "fr/MCV/test/data_online_transcription.tsv", }, "it.MCV": { "offline": _DL_URL + "it/MCV/test/offline/data.tar.gz", "online": _DL_URL + "it/MCV/test/online/data.tar.gz", "offline_transcription" : _TR_URL + "it/MCV/test/data_offline_transcription.tsv", "online_transcription" : _TR_URL + "it/MCV/test/data_online_transcription.tsv", }, "all": { "de.MCV.offline": _DL_URL + "de/MCV/test/offline/data.tar.gz", "de.MCV.online": _DL_URL + "de/MCV/test/online/data.tar.gz", "en.LS-clean.offline": _DL_URL + "en/LS-clean/test/offline/data.tar.gz", "en.LS-clean.online": _DL_URL + "en/LS-clean/test/online/data.tar.gz", "en.LS-other.offline": _DL_URL + "en/LS-other/test/offline/data.tar.gz", "en.LS-other.online": _DL_URL + "en/LS-other/test/online/data.tar.gz", "en.MCV.offline": _DL_URL + "en/MCV/test/offline/data.tar.gz", "en.MCV.online": _DL_URL + "en/MCV/test/online/data.tar.gz", "es.MCV.offline": _DL_URL + "es/MCV/test/offline/data.tar.gz", "es.MCV.online": _DL_URL + "es/MCV/test/online/data.tar.gz", "fr.MCV.offline": _DL_URL + "fr/MCV/test/offline/data.tar.gz", "fr.MCV.online": _DL_URL + "fr/MCV/test/online/data.tar.gz", "it.MCVoffline": _DL_URL + "it/MCV/test/offline/data.tar.gz", "it.MCV.online": _DL_URL + "it/MCV/test/online/data.tar.gz", "de.MCV.offline_transcription" : _TR_URL + "de/MCV/test/data_offline_transcription.tsv", "de.MCV.online_transcription" : _TR_URL + "de/MCV/test/data_online_transcription.tsv", "en.LS-clean.offline_transcription" : _TR_URL + "en/LS-clean/test/data_offline_transcription.tsv", "en.LS-clean.online_transcription" : _TR_URL + "en/LS-clean/test/data_online_transcription.tsv", "en.LS-other.offline_transcription" : _TR_URL + "en/LS-other/test/data_offline_transcription.tsv", "en.LS-other.online_transcription" : _TR_URL + "en/LS-other/test/data_online_transcription.tsv", "en.MCV.offline_transcription" : _TR_URL + "en/MCV/test/data_offline_transcription.tsv", "en.MCVonline_transcription" : _TR_URL + "en/MCV/test/data_online_transcription.tsv", "es.MCV.offline_transcription" : _TR_URL + "es/MCV/test/data_offline_transcription.tsv", "es.MCV.online_transcription" : _TR_URL + "es/MCV/test/data_online_transcription.tsv", "fr.MCV.offline_transcription" : _TR_URL + "fr/MCV/test/data_offline_transcription.tsv", "fr.MCV.online_transcription" : _TR_URL + "fr/MCV/test/data_online_transcription.tsv", "it.MCV.offline_transcription" : _TR_URL + "it/MCV/test/data_offline_transcription.tsv", "it.MCV.online_transcription" : _TR_URL + "it/MCV/test/data_online_transcription.tsv", } } logger = datasets.logging.get_logger(__name__) class MocksConfig(datasets.BuilderConfig): """BuilderConfig for MOCKS testset.""" def __init__(self, name, version, **kwargs): super(MocksConfig, self).__init__( name=name, version=datasets.Version(version), description=description, **kwargs, ) class Mocks(datasets.GeneratorBasedBuilder): """Mocks Dataset.""" DEFAULT_CONFIG_NAME = "all" BUILDER_CONFIGS = [ datasets.BuilderConfig(name="de.MCV", description="German Mozilla Common Voice."), datasets.BuilderConfig(name="en.LS-clean", description="English LibriSpeech 'Clean'."), datasets.BuilderConfig(name="en.LS-other", description="English LibriSpeech 'Other'."), datasets.BuilderConfig(name="en.MCV", description="English Mozilla Common Voice."), datasets.BuilderConfig(name="es.MCV", description="Spanish Mozilla Common Voice."), datasets.BuilderConfig(name="fr.MCV", description="French Mozilla Common Voice."), datasets.BuilderConfig(name="it.MCV", description="Italian Mozilla Common Voice."), datasets.BuilderConfig(name="all", description="All test set."), ] def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "audio_id": datasets.Value("string"), "audio": datasets.Audio(sampling_rate=16_000), "transcription": datasets.Value("string"), "type": datasets.Value("string") } ), supervised_keys=("file", "text"), homepage=_BASE_URL, citation=_CITATION ) def _split_generators(self, dl_manager): archive_path = dl_manager.download(_DL_URLS[self.config.name]) # (Optional) In non-streaming mode, we can extract the archive locally to have actual local audio files: local_extracted_archive = dl_manager.extract(archive_path) if not dl_manager.is_streaming else {} if self.config.name == "de.MCV": offline_split = [ datasets.SplitGenerator( name="offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("offline"), "audio_files": dl_manager.iter_archive(archive_path["offline"]), "transcription": dl_manager.download_and_extract(archive_path["offline_transcription"]), "s_type": "offline" } ) ] online_split = [ datasets.SplitGenerator( name="online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("online"), "audio_files": dl_manager.iter_archive(archive_path["online"]), "transcription": dl_manager.download_and_extract(archive_path["online_transcription"]), "s_type": "online" } ) ] elif self.config.name == "en.LS-clean": offline_split = [ datasets.SplitGenerator( name="offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("offline"), "audio_files": dl_manager.iter_archive(archive_path["offline"]), "transcription": dl_manager.download_and_extract(archive_path["offline_transcription"]), "s_type": "offline" } ) ] online_split = [ datasets.SplitGenerator( name="online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("online"), "audio_files": dl_manager.iter_archive(archive_path["online"]), "transcription": dl_manager.download_and_extract(archive_path["online_transcription"]), "s_type": "online" } ) ] elif self.config.name == "en.LS-other": offline_split = [ datasets.SplitGenerator( name="offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("offline"), "audio_files": dl_manager.iter_archive(archive_path["offline"]), "transcription": dl_manager.download_and_extract(archive_path["offline_transcription"]), "s_type": "offline" } ) ] online_split = [ datasets.SplitGenerator( name="online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("online"), "audio_files": dl_manager.iter_archive(archive_path["online"]), "transcription": dl_manager.download_and_extract(archive_path["online_transcription"]), "s_type": "online" } ) ] elif self.config.name == "en.MCV": offline_split = [ datasets.SplitGenerator( name="offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("offline"), "audio_files": dl_manager.iter_archive(archive_path["offline"]), "transcription": dl_manager.download_and_extract(archive_path["offline_transcription"]), "s_type": "offline" } ) ] online_split = [ datasets.SplitGenerator( name="online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("online"), "audio_files": dl_manager.iter_archive(archive_path["online"]), "transcription": dl_manager.download_and_extract(archive_path["online_transcription"]), "s_type": "online" } ) ] elif self.config.name == "es.MCV": offline_split = [ datasets.SplitGenerator( name="offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("offline"), "audio_files": dl_manager.iter_archive(archive_path["offline"]), "transcription": dl_manager.download_and_extract(archive_path["offline_transcription"]), "s_type": "offline" } ) ] online_split = [ datasets.SplitGenerator( name="online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("online"), "audio_files": dl_manager.iter_archive(archive_path["online"]), "transcription": dl_manager.download_and_extract(archive_path["online_transcription"]), "s_type": "online" } ) ] elif self.config.name == "fr.MCV": offline_split = [ datasets.SplitGenerator( name="offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("offline"), "audio_files": dl_manager.iter_archive(archive_path["offline"]), "transcription": dl_manager.download_and_extract(archive_path["offline_transcription"]), "s_type": "offline" } ) ] online_split = [ datasets.SplitGenerator( name="online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("online"), "audio_files": dl_manager.iter_archive(archive_path["online"]), "transcription": dl_manager.download_and_extract(archive_path["online_transcription"]), "s_type": "online" } ) ] elif self.config.name == "it.MCV": offline_split = [ datasets.SplitGenerator( name="offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("offline"), "audio_files": dl_manager.iter_archive(archive_path["offline"]), "transcription": dl_manager.download_and_extract(archive_path["offline_transcription"]), "s_type": "offline" } ) ] online_split = [ datasets.SplitGenerator( name="online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("online"), "audio_files": dl_manager.iter_archive(archive_path["online"]), "transcription": dl_manager.download_and_extract(archive_path["online_transcription"]), "s_type": "online" } ) ] elif self.config.name == "all": offline_split = [ datasets.SplitGenerator( name="de.MCV.offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("de.MCV.offline"), "audio_files": dl_manager.iter_archive(archive_path["de.MCV.offline"]), "transcription": dl_manager.download_and_extract(archive_path["de.MCV.offline_transcription"]), "s_type": "offline" } ), datasets.SplitGenerator( name="en.LS-clean.offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("en.LS-clean.offline"), "audio_files": dl_manager.iter_archive(archive_path["en.LS-clean.offline"]), "transcription": dl_manager.download_and_extract(archive_path["en.LS-clean.offline_transcription"]), "s_type": "offline" } ), datasets.SplitGenerator( name="en.LS-other.offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("en.LS-other.offline"), "audio_files": dl_manager.iter_archive(archive_path["en.LS-other.offline"]), "transcription": dl_manager.download_and_extract(archive_path["en.LS-other.offline_transcription"]), "s_type": "offline" } ), datasets.SplitGenerator( name="en.MCV.offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("en.MCV.offline"), "audio_files": dl_manager.iter_archive(archive_path["en.MCV.offline"]), "transcription": dl_manager.download_and_extract(archive_path["en.MCV.offline_transcription"]), "s_type": "offline" } ), datasets.SplitGenerator( name="es.MCV.offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("es.MCV.offline"), "audio_files": dl_manager.iter_archive(archive_path["es.MCV.offline"]), "transcription": dl_manager.download_and_extract(archive_path["es.MCV.offline_transcription"]), "s_type": "offline" } ), datasets.SplitGenerator( name="fr.MCV.offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("fr.MCV.offline"), "audio_files": dl_manager.iter_archive(archive_path["fr.MCV.offline"]), "transcription": dl_manager.download_and_extract(archive_path["fr.MCV.offline_transcription"]), "s_type": "offline" } ), datasets.SplitGenerator( name="it.MCV.offline", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("it.MCV.offline"), "audio_files": dl_manager.iter_archive(archive_path["it.MCV.offline"]), "transcription": dl_manager.download_and_extract(archive_path["it.MCV.offline_transcription"]), "s_type": "offline" } ) ] online_split = [ datasets.SplitGenerator( name="de.MCV.online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("de.MCV.online"), "audio_files": dl_manager.iter_archive(archive_path["de.MCV.online"]), "transcription": dl_manager.download_and_extract(archive_path["de.MCV.offline_transconline"]), "s_type": "online" } ), datasets.SplitGenerator( name="en.LS-clean.online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("en.LS-clean.online"), "audio_files": dl_manager.iter_archive(archive_path["en.LS-clean.online"]), "transcription": dl_manager.download_and_extract(archive_path["en.LS-clean.online_transcription"]), "s_type": "online" } ), datasets.SplitGenerator( name="en.LS-other.online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("en.LS-other.online"), "audio_files": dl_manager.iter_archive(archive_path["en.LS-other.online"]), "transcription": dl_manager.download_and_extract(archive_path["en.LS-other.online_transcription"]), "s_type": "online" } ), datasets.SplitGenerator( name="en.MCV.online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("en.MCV.online"), "audio_files": dl_manager.iter_archive(archive_path["en.MCV.online"]), "transcription": dl_manager.download_and_extract(archive_path["en.MCV.online_transcription"]), "s_type": "online" } ), datasets.SplitGenerator( name="es.MCV.online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("es.MCV.online"), "audio_files": dl_manager.iter_archive(archive_path["es.MCV.online"]), "transcription": dl_manager.download_and_extract(archive_path["es.MCV.online_transcription"]), "s_type": "online" } ), datasets.SplitGenerator( name="fr.MCV.online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("fr.MCV.online"), "audio_files": dl_manager.iter_archive(archive_path["fr.MCV.online"]), "transcription": dl_manager.download_and_extract(archive_path["fr.MCV.online_transcription"]), "s_type": "online" } ), datasets.SplitGenerator( name="it.MCV.online", gen_kwargs={ "local_extracted_archive": local_extracted_archive.get("it.MCV.online"), "audio_files": dl_manager.iter_archive(archive_path["it.MCV.online"]), "transcription": dl_manager.download_and_extract(archive_path["it.MCV.online_transcription"]), "s_type": "online" } ) ] return online_split + offline_split def _generate_examples(self, local_extracted_archive, audio_files, transcription, s_type): """Lorem ipsum.""" metadata = {} trans_col_name = "keyword_transcription" if s_type == "online": trans_col_name = "adversary_keyword_transcription" with open(transcription, encoding="utf-8") as f: for row in f: r = row.split(r"\t") print(row) audio_id = r[0].split("/")[-1] keyword = r[1] metadata[audio_id] = {"audio_id": audio_id, trans_col_name: ngram} inside_clips_dir = True id_ = 0 for path, f in audio_files: _, audio_name = os.path.split(path) if audio_name in metadata: audio = {"bytes": f.read()} yield id_, {**metadata[audio_id], "audio": audio} id_ +=1