File size: 7,540 Bytes
5a9f628 7c40382 5a9f628 7c40382 57c9024 7c40382 5a9f628 7c40382 5a9f628 7c40382 5a9f628 7c40382 5a9f628 7c40382 57c9024 7c40382 57c9024 7c40382 5a9f628 7c40382 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# 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 datasets
logger = datasets.logging.get_logger(__name__)
_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"
_BASE_URL = "https://huggingface.co/datasets/mikolaj-p/MOCKS-test/tree/main"
_DL_URLS_TEMPLATE = {
"data": "%s/%s/test/%s/data.tar.gz",
"transcription" : "%s/%s/test/data_%s_transcription.tsv",
"positive" : "%s/%s/test/%s/all.pair.positive.tsv",
"similar" : "%s/%s/test/%s/all.pair.similar.tsv",
"different" : "%s/%s/test/%s/all.pair.different.tsv",
"positive_subset" : "%s/%s/test/%s/subset.pair.positive.tsv",
"similar_subset" : "%s/%s/test/%s/subset.pair.similar.tsv",
"different_subset" : "%s/%s/test/%s/subset.pair.different.tsv",
}
_MOCKS_SETS = [
"en.LS-clean"]
# "en.LS-other",
# "en.MCV",
# "de.MCV",
# "es.MCV",
# "fr.MCV",
# "it.MCV"]
_MOCKS_SUFFIXES = [
"",
".positive",
".similar",
".different",
".subset",
".positive_subset",
".similar_subset",
".different_subset"]
class Mocks(datasets.GeneratorBasedBuilder):
"""Mocks Dataset."""
DEFAULT_CONFIG_NAME = "en.LS-clean"
BUILDER_CONFIGS = [datasets.BuilderConfig(name=subset+suffix, description=subset+suffix)
for subset in _MOCKS_SETS for suffix in _MOCKS_SUFFIXES]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features({
"keyword_id": datasets.Value("string"),
"keyword_transcription": datasets.Value("string"),
"test_id": datasets.Value("string"),
"test_transcription": datasets.Value("string"),
"test_audio": datasets.Audio(sampling_rate=16000),
"label": datasets.Value("bool"),
}
),
homepage=_BASE_URL,
citation=_CITATION
)
def _split_generators(self, dl_manager):
logger.info("split_generator")
name_split = self.config.name.split(".")
subset_lang = name_split[0]
subset_name = name_split[1]
if len(name_split) == 2:
pairs_types = ["positive", "similar", "different"]
elif name_split[2] == "subset":
pairs_types = ["positive_subset", "similar_subset", "different_subset"]
else:
pairs_types = [name_split[2]]
offline_archive_path = dl_manager.download({
k: v%(subset_lang, subset_name, "offline")
for k, v in _DL_URLS_TEMPLATE.items()
})
online_archive_path = dl_manager.download({
k: v%(subset_lang, subset_name, "online")
for k, v in _DL_URLS_TEMPLATE.items()
})
split_offline = [datasets.SplitGenerator(
name="offline",
gen_kwargs={
"audio_files": dl_manager.iter_archive(offline_archive_path["data"]),
"transcription_keyword": offline_archive_path["transcription"],
"transcription_test": offline_archive_path["transcription"],
"pairs": [offline_archive_path[pair_type] for pair_type in pairs_types],
}
)
]
split_online = [datasets.SplitGenerator(
name="online",
gen_kwargs={
"audio_files": dl_manager.iter_archive(online_archive_path["data"]),
"transcription_keyword": offline_archive_path["transcription"],
"transcription_test": online_archive_path["transcription"],
"pairs": [online_archive_path[pair_type] for pair_type in pairs_types],
}
)
]
return split_offline + split_online
def _read_transcription(self, transcription_path):
transcription_metadata = {}
with open(transcription_path, encoding="utf-8") as f:
reader = csv.reader(f, delimiter="\t")
next(reader, None)
for row in reader:
_, audio_id = os.path.split(row[0])
transcription = row[1]
transcription_metadata[audio_id] = {
"audio_id": audio_id,
"transcription": transcription}
return transcription_metadata
def _generate_examples(self, audio_files, transcription_keyword, transcription_test, pairs):
transcription_keyword_metadata = self._read_transcription(transcription_keyword)
transcription_test_metadata = self._read_transcription(transcription_test)
pair_metadata = {}
for pair in pairs:
with open(pair, encoding="utf-8") as f:
reader = csv.reader(f, delimiter="\t")
next(reader, None)
for row in reader:
_, keyword_id = os.path.split(row[0])
_, test_id = os.path.split(row[1])
if keyword_id not in transcription_keyword_metadata:
logger.error("No transcription and audio for keyword %s"%(keyword_id))
continue
if test_id not in transcription_test_metadata:
logger.error("No transcription and audio for test case %s"%(test_id))
continue
if test_id not in pair_metadata:
pair_metadata[test_id] = []
pair_metadata[test_id].append([keyword_id, int(row[-1])])
id_ = 0
for test_path, test_f in audio_files:
_, test_id = os.path.split(test_path)
if test_id in pair_metadata:
test_audio = {"bytes": test_f.read()}
for keyword_id, label in pair_metadata[test_id]:
yield id_, {
"keyword_id": keyword_id,
"keyword_transcription": transcription_keyword_metadata[keyword_id]["transcription"],
"test_id": test_id,
"test_transcription": transcription_test_metadata[test_id]["transcription"],
"test_audio": test_audio,
"label": label}
id_ += 1
|