refactor_loader_script
#9
by
mikolaj-p
- opened
MOCKS.py
CHANGED
@@ -41,401 +41,164 @@ audio testset for evaluation and benchmarking Open-Vocabulary Keyword Spotting (
|
|
41 |
|
42 |
|
43 |
_BASE_URL = "https://huggingface.co/datasets/voiceintelligenceresearch/MOCKS/tree/main"
|
44 |
-
|
45 |
-
"
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
"
|
52 |
-
|
53 |
-
"online": "en/LS-clean/test/online/data.tar.gz",
|
54 |
-
"offline_transcription" : "en/LS-clean/test/data_offline_transcription.tsv",
|
55 |
-
"online_transcription" : "en/LS-clean/test/data_online_transcription.tsv",
|
56 |
-
},
|
57 |
-
"en.LS-other": {
|
58 |
-
"offline": "en/LS-other/test/offline/data.tar.gz",
|
59 |
-
"online": "en/LS-other/test/online/data.tar.gz",
|
60 |
-
"offline_transcription" : "en/LS-other/test/data_offline_transcription.tsv",
|
61 |
-
"online_transcription" : "en/LS-other/test/data_online_transcription.tsv",
|
62 |
-
},
|
63 |
-
"en.MCV": {
|
64 |
-
"offline": "en/MCV/test/offline/data.tar.gz",
|
65 |
-
"online": "en/MCV/test/online/data.tar.gz",
|
66 |
-
"offline_transcription" : "en/MCV/test/data_offline_transcription.tsv",
|
67 |
-
"online_transcription" : "en/MCV/test/data_online_transcription.tsv",
|
68 |
-
},
|
69 |
-
"es.MCV": {
|
70 |
-
"offline": "es/MCV/test/offline/data.tar.gz",
|
71 |
-
"online": "es/MCV/test/online/data.tar.gz",
|
72 |
-
"offline_transcription" : "es/MCV/test/data_offline_transcription.tsv",
|
73 |
-
"online_transcription" : "es/MCV/test/data_online_transcription.tsv",
|
74 |
-
},
|
75 |
-
"fr.MCV": {
|
76 |
-
"offline": "fr/MCV/test/offline/data.tar.gz",
|
77 |
-
"online": "fr/MCV/test/online/data.tar.gz",
|
78 |
-
"offline_transcription": "fr/MCV/test/data_offline_transcription.tsv",
|
79 |
-
"online_transcription": "fr/MCV/test/data_online_transcription.tsv",
|
80 |
-
},
|
81 |
-
"it.MCV": {
|
82 |
-
"offline": "it/MCV/test/offline/data.tar.gz",
|
83 |
-
"online": "it/MCV/test/online/data.tar.gz",
|
84 |
-
"offline_transcription": "it/MCV/test/data_offline_transcription.tsv",
|
85 |
-
"online_transcription": "it/MCV/test/data_online_transcription.tsv",
|
86 |
-
},
|
87 |
-
"all": {
|
88 |
-
"de.MCV.offline": "de/MCV/test/offline/data.tar.gz",
|
89 |
-
"de.MCV.online": "de/MCV/test/online/data.tar.gz",
|
90 |
-
"en.LS-clean.offline": "en/LS-clean/test/offline/data.tar.gz",
|
91 |
-
"en.LS-clean.online": "en/LS-clean/test/online/data.tar.gz",
|
92 |
-
"en.LS-other.offline": "en/LS-other/test/offline/data.tar.gz",
|
93 |
-
"en.LS-other.online": "en/LS-other/test/online/data.tar.gz",
|
94 |
-
"en.MCV.offline": "en/MCV/test/offline/data.tar.gz",
|
95 |
-
"en.MCV.online": "en/MCV/test/online/data.tar.gz",
|
96 |
-
"es.MCV.offline": "es/MCV/test/offline/data.tar.gz",
|
97 |
-
"es.MCV.online": "es/MCV/test/online/data.tar.gz",
|
98 |
-
"fr.MCV.offline": "fr/MCV/test/offline/data.tar.gz",
|
99 |
-
"fr.MCV.online": "fr/MCV/test/online/data.tar.gz",
|
100 |
-
"it.MCV.offline": "it/MCV/test/offline/data.tar.gz",
|
101 |
-
"it.MCV.online": "it/MCV/test/online/data.tar.gz",
|
102 |
-
"de.MCV.offline_transcription": "de/MCV/test/data_offline_transcription.tsv",
|
103 |
-
"de.MCV.online_transcription": "de/MCV/test/data_online_transcription.tsv",
|
104 |
-
"en.LS-clean.offline_transcription": "en/LS-clean/test/data_offline_transcription.tsv",
|
105 |
-
"en.LS-clean.online_transcription": "en/LS-clean/test/data_online_transcription.tsv",
|
106 |
-
"en.LS-other.offline_transcription": "en/LS-other/test/data_offline_transcription.tsv",
|
107 |
-
"en.LS-other.online_transcription": "en/LS-other/test/data_online_transcription.tsv",
|
108 |
-
"en.MCV.offline_transcription": "en/MCV/test/data_offline_transcription.tsv",
|
109 |
-
"en.MCV.online_transcription": "en/MCV/test/data_online_transcription.tsv",
|
110 |
-
"es.MCV.offline_transcription": "es/MCV/test/data_offline_transcription.tsv",
|
111 |
-
"es.MCV.online_transcription": "es/MCV/test/data_online_transcription.tsv",
|
112 |
-
"fr.MCV.offline_transcription": "fr/MCV/test/data_offline_transcription.tsv",
|
113 |
-
"fr.MCV.online_transcription": "fr/MCV/test/data_online_transcription.tsv",
|
114 |
-
"it.MCV.offline_transcription": "it/MCV/test/data_offline_transcription.tsv",
|
115 |
-
"it.MCV.online_transcription": "it/MCV/test/data_online_transcription.tsv",
|
116 |
-
}
|
117 |
}
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
class Mocks(datasets.GeneratorBasedBuilder):
|
121 |
"""Mocks Dataset."""
|
122 |
-
DEFAULT_CONFIG_NAME = "
|
123 |
-
|
124 |
-
BUILDER_CONFIGS = [
|
125 |
-
|
126 |
-
datasets.BuilderConfig(name="en.LS-clean", description="English LibriSpeech 'Clean'."),
|
127 |
-
datasets.BuilderConfig(name="en.LS-other", description="English LibriSpeech 'Other'."),
|
128 |
-
datasets.BuilderConfig(name="en.MCV", description="English Mozilla Common Voice."),
|
129 |
-
datasets.BuilderConfig(name="es.MCV", description="Spanish Mozilla Common Voice."),
|
130 |
-
datasets.BuilderConfig(name="fr.MCV", description="French Mozilla Common Voice."),
|
131 |
-
datasets.BuilderConfig(name="it.MCV", description="Italian Mozilla Common Voice."),
|
132 |
-
datasets.BuilderConfig(name="all", description="All test set."),
|
133 |
-
]
|
134 |
|
135 |
def _info(self):
|
136 |
return datasets.DatasetInfo(
|
137 |
description=_DESCRIPTION,
|
138 |
-
features=datasets.Features(
|
139 |
-
|
140 |
-
"
|
141 |
-
"
|
142 |
-
"
|
|
|
|
|
143 |
}
|
144 |
),
|
145 |
homepage=_BASE_URL,
|
146 |
citation=_CITATION
|
147 |
)
|
148 |
|
|
|
149 |
def _split_generators(self, dl_manager):
|
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 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
elif self.config.name == "es.MCV":
|
241 |
-
offline_split = [
|
242 |
-
datasets.SplitGenerator(
|
243 |
-
name="offline",
|
244 |
-
gen_kwargs={
|
245 |
-
"audio_files": dl_manager.iter_archive(archive_path["offline"]),
|
246 |
-
"transcription": archive_path["offline_transcription"],
|
247 |
-
"s_type": "offline"
|
248 |
-
}
|
249 |
-
)
|
250 |
-
]
|
251 |
-
online_split = [
|
252 |
-
datasets.SplitGenerator(
|
253 |
-
name="online",
|
254 |
-
gen_kwargs={
|
255 |
-
"audio_files": dl_manager.iter_archive(archive_path["online"]),
|
256 |
-
"transcription": archive_path["online_transcription"],
|
257 |
-
"s_type": "online"
|
258 |
-
}
|
259 |
-
)
|
260 |
-
]
|
261 |
-
|
262 |
-
elif self.config.name == "fr.MCV":
|
263 |
-
offline_split = [
|
264 |
-
datasets.SplitGenerator(
|
265 |
-
name="offline",
|
266 |
-
gen_kwargs={
|
267 |
-
"audio_files": dl_manager.iter_archive(archive_path["offline"]),
|
268 |
-
"transcription": archive_path["offline_transcription"],
|
269 |
-
"s_type": "offline"
|
270 |
-
}
|
271 |
-
)
|
272 |
-
]
|
273 |
-
online_split = [
|
274 |
-
datasets.SplitGenerator(
|
275 |
-
name="online",
|
276 |
-
gen_kwargs={
|
277 |
-
"audio_files": dl_manager.iter_archive(archive_path["online"]),
|
278 |
-
"transcription": archive_path["online_transcription"],
|
279 |
-
"s_type": "online"
|
280 |
-
}
|
281 |
-
)
|
282 |
-
]
|
283 |
-
|
284 |
-
elif self.config.name == "it.MCV":
|
285 |
-
offline_split = [
|
286 |
-
datasets.SplitGenerator(
|
287 |
-
name="offline",
|
288 |
-
gen_kwargs={
|
289 |
-
"audio_files": dl_manager.iter_archive(archive_path["offline"]),
|
290 |
-
"transcription": archive_path["offline_transcription"],
|
291 |
-
"s_type": "offline"
|
292 |
-
}
|
293 |
-
)
|
294 |
-
]
|
295 |
-
online_split = [
|
296 |
-
datasets.SplitGenerator(
|
297 |
-
name="online",
|
298 |
-
gen_kwargs={
|
299 |
-
"audio_files": dl_manager.iter_archive(archive_path["online"]),
|
300 |
-
"transcription": archive_path["online_transcription"],
|
301 |
-
"s_type": "online"
|
302 |
-
}
|
303 |
-
)
|
304 |
-
]
|
305 |
-
|
306 |
-
elif self.config.name == "all":
|
307 |
-
offline_split = [
|
308 |
-
datasets.SplitGenerator(
|
309 |
-
name="de.MCV.offline",
|
310 |
-
gen_kwargs={
|
311 |
-
"audio_files": dl_manager.iter_archive(archive_path["de.MCV.offline"]),
|
312 |
-
"transcription": archive_path["de.MCV.offline_transcription"],
|
313 |
-
"s_type": "offline"
|
314 |
-
}
|
315 |
-
),
|
316 |
-
datasets.SplitGenerator(
|
317 |
-
name="en.LS-clean.offline",
|
318 |
-
gen_kwargs={
|
319 |
-
"audio_files": dl_manager.iter_archive(archive_path["en.LS-clean.offline"]),
|
320 |
-
"transcription": archive_path["en.LS-clean.offline_transcription"],
|
321 |
-
"s_type": "offline"
|
322 |
-
}
|
323 |
-
),
|
324 |
-
datasets.SplitGenerator(
|
325 |
-
name="en.LS-other.offline",
|
326 |
-
gen_kwargs={
|
327 |
-
"audio_files": dl_manager.iter_archive(archive_path["en.LS-other.offline"]),
|
328 |
-
"transcription": archive_path["en.LS-other.offline_transcription"],
|
329 |
-
"s_type": "offline"
|
330 |
-
}
|
331 |
-
),
|
332 |
-
datasets.SplitGenerator(
|
333 |
-
name="en.MCV.offline",
|
334 |
-
gen_kwargs={
|
335 |
-
"audio_files": dl_manager.iter_archive(archive_path["en.MCV.offline"]),
|
336 |
-
"transcription": archive_path["en.MCV.offline_transcription"],
|
337 |
-
"s_type": "offline"
|
338 |
-
}
|
339 |
-
),
|
340 |
-
datasets.SplitGenerator(
|
341 |
-
name="es.MCV.offline",
|
342 |
-
gen_kwargs={
|
343 |
-
"audio_files": dl_manager.iter_archive(archive_path["es.MCV.offline"]),
|
344 |
-
"transcription": archive_path["es.MCV.offline_transcription"],
|
345 |
-
"s_type": "offline"
|
346 |
-
}
|
347 |
-
),
|
348 |
-
datasets.SplitGenerator(
|
349 |
-
name="fr.MCV.offline",
|
350 |
-
gen_kwargs={
|
351 |
-
"audio_files": dl_manager.iter_archive(archive_path["fr.MCV.offline"]),
|
352 |
-
"transcription": archive_path["fr.MCV.offline_transcription"],
|
353 |
-
"s_type": "offline"
|
354 |
-
}
|
355 |
-
),
|
356 |
-
datasets.SplitGenerator(
|
357 |
-
name="it.MCV.offline",
|
358 |
-
gen_kwargs={
|
359 |
-
"audio_files": dl_manager.iter_archive(archive_path["it.MCV.offline"]),
|
360 |
-
"transcription": archive_path["it.MCV.offline_transcription"],
|
361 |
-
"s_type": "offline"
|
362 |
-
}
|
363 |
-
)
|
364 |
-
]
|
365 |
-
online_split = [
|
366 |
-
datasets.SplitGenerator(
|
367 |
-
name="de.MCV.online",
|
368 |
-
gen_kwargs={
|
369 |
-
"transcription": archive_path["de.MCV.offline_transconline"],
|
370 |
-
"s_type": "online"
|
371 |
-
}
|
372 |
-
),
|
373 |
-
datasets.SplitGenerator(
|
374 |
-
name="en.LS-clean.online",
|
375 |
-
gen_kwargs={
|
376 |
-
"audio_files": dl_manager.iter_archive(archive_path["en.LS-clean.online"]),
|
377 |
-
"transcription": archive_path["en.LS-clean.online_transcription"],
|
378 |
-
"s_type": "online"
|
379 |
-
}
|
380 |
-
),
|
381 |
-
datasets.SplitGenerator(
|
382 |
-
name="en.LS-other.online",
|
383 |
-
gen_kwargs={
|
384 |
-
"audio_files": dl_manager.iter_archive(archive_path["en.LS-other.online"]),
|
385 |
-
"transcription": archive_path["en.LS-other.online_transcription"],
|
386 |
-
"s_type": "online"
|
387 |
-
}
|
388 |
-
),
|
389 |
-
datasets.SplitGenerator(
|
390 |
-
name="en.MCV.online",
|
391 |
-
gen_kwargs={
|
392 |
-
"audio_files": dl_manager.iter_archive(archive_path["en.MCV.online"]),
|
393 |
-
"transcription": archive_path["en.MCV.online_transcription"],
|
394 |
-
"s_type": "online"
|
395 |
-
}
|
396 |
-
),
|
397 |
-
datasets.SplitGenerator(
|
398 |
-
name="es.MCV.online",
|
399 |
-
gen_kwargs={
|
400 |
-
"audio_files": dl_manager.iter_archive(archive_path["es.MCV.online"]),
|
401 |
-
"transcription": archive_path["es.MCV.online_transcription"],
|
402 |
-
"s_type": "online"
|
403 |
-
}
|
404 |
-
),
|
405 |
-
datasets.SplitGenerator(
|
406 |
-
name="fr.MCV.online",
|
407 |
-
gen_kwargs={
|
408 |
-
"audio_files": dl_manager.iter_archive(archive_path["fr.MCV.online"]),
|
409 |
-
"transcription": archive_path["fr.MCV.online_transcription"],
|
410 |
-
"s_type": "online"
|
411 |
-
}
|
412 |
-
),
|
413 |
-
datasets.SplitGenerator(
|
414 |
-
name="it.MCV.online",
|
415 |
-
gen_kwargs={
|
416 |
-
"audio_files": dl_manager.iter_archive(archive_path["it.MCV.online"]),
|
417 |
-
"transcription": archive_path["it.MCV.online_transcription"],
|
418 |
-
"s_type": "online"
|
419 |
-
}
|
420 |
-
)
|
421 |
-
]
|
422 |
-
|
423 |
-
return online_split + offline_split
|
424 |
-
|
425 |
-
def _generate_examples(self, audio_files, transcription, s_type):
|
426 |
-
"""Lorem ipsum."""
|
427 |
-
metadata = {}
|
428 |
-
with open(transcription, encoding="utf-8") as f:
|
429 |
-
f = csv.reader(f, delimiter="\t")
|
430 |
-
for row in f:
|
431 |
-
audio_id = row[0].split("/")[-1]
|
432 |
-
keyword_transcription = row[1]
|
433 |
-
metadata[audio_id] = {"audio_id": audio_id, "transcription": keyword_transcription}
|
434 |
|
435 |
id_ = 0
|
436 |
-
for
|
437 |
-
_,
|
438 |
-
if
|
439 |
-
|
440 |
-
|
441 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
|
43 |
_BASE_URL = "https://huggingface.co/datasets/voiceintelligenceresearch/MOCKS/tree/main"
|
44 |
+
_DL_URLS_TEMPLATE = {
|
45 |
+
"data": "%s/%s/test/%s/data.tar.gz",
|
46 |
+
"transcription" : "%s/%s/test/data_%s_transcription.tsv",
|
47 |
+
"positive" : "%s/%s/test/%s/all.pair.positive.tsv",
|
48 |
+
"similar" : "%s/%s/test/%s/all.pair.similar.tsv",
|
49 |
+
"different" : "%s/%s/test/%s/all.pair.different.tsv",
|
50 |
+
"positive_subset" : "%s/%s/test/%s/subset.pair.positive.tsv",
|
51 |
+
"similar_subset" : "%s/%s/test/%s/subset.pair.similar.tsv",
|
52 |
+
"different_subset" : "%s/%s/test/%s/subset.pair.different.tsv",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
}
|
54 |
|
55 |
+
_MOCKS_SETS = [
|
56 |
+
"en.LS-clean",
|
57 |
+
"en.LS-other",
|
58 |
+
"en.MCV",
|
59 |
+
"de.MCV",
|
60 |
+
"es.MCV",
|
61 |
+
"fr.MCV",
|
62 |
+
"it.MCV"]
|
63 |
+
|
64 |
+
_MOCKS_SUFFIXES = [
|
65 |
+
"",
|
66 |
+
".positive",
|
67 |
+
".similar",
|
68 |
+
".different",
|
69 |
+
".subset",
|
70 |
+
".positive_subset",
|
71 |
+
".similar_subset",
|
72 |
+
".different_subset"]
|
73 |
+
|
74 |
|
75 |
class Mocks(datasets.GeneratorBasedBuilder):
|
76 |
"""Mocks Dataset."""
|
77 |
+
DEFAULT_CONFIG_NAME = "en.LS-clean"
|
78 |
+
|
79 |
+
BUILDER_CONFIGS = [datasets.BuilderConfig(name=subset+suffix, description=subset+suffix)
|
80 |
+
for subset in _MOCKS_SETS for suffix in _MOCKS_SUFFIXES]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
def _info(self):
|
83 |
return datasets.DatasetInfo(
|
84 |
description=_DESCRIPTION,
|
85 |
+
features=datasets.Features({
|
86 |
+
"keyword_id": datasets.Value("string"),
|
87 |
+
"keyword_transcription": datasets.Value("string"),
|
88 |
+
"test_id": datasets.Value("string"),
|
89 |
+
"test_transcription": datasets.Value("string"),
|
90 |
+
"test_audio": datasets.Audio(sampling_rate=16000),
|
91 |
+
"label": datasets.Value("bool"),
|
92 |
}
|
93 |
),
|
94 |
homepage=_BASE_URL,
|
95 |
citation=_CITATION
|
96 |
)
|
97 |
|
98 |
+
|
99 |
def _split_generators(self, dl_manager):
|
100 |
+
logger.info("split_generator")
|
101 |
+
name_split = self.config.name.split(".")
|
102 |
+
subset_lang = name_split[0]
|
103 |
+
subset_name = name_split[1]
|
104 |
+
|
105 |
+
if len(name_split) == 2:
|
106 |
+
pairs_types = ["positive", "similar", "different"]
|
107 |
+
elif name_split[2] == "subset":
|
108 |
+
pairs_types = ["positive_subset", "similar_subset", "different_subset"]
|
109 |
+
else:
|
110 |
+
pairs_types = [name_split[2]]
|
111 |
+
|
112 |
+
offline_archive_path = dl_manager.download({
|
113 |
+
k: v%(subset_lang, subset_name, "offline")
|
114 |
+
for k, v in _DL_URLS_TEMPLATE.items()
|
115 |
+
})
|
116 |
+
online_archive_path = dl_manager.download({
|
117 |
+
k: v%(subset_lang, subset_name, "online")
|
118 |
+
for k, v in _DL_URLS_TEMPLATE.items()
|
119 |
+
})
|
120 |
+
|
121 |
+
split_offline = [datasets.SplitGenerator(
|
122 |
+
name="offline",
|
123 |
+
gen_kwargs={
|
124 |
+
"audio_files": dl_manager.iter_archive(offline_archive_path["data"]),
|
125 |
+
"transcription_keyword": offline_archive_path["transcription"],
|
126 |
+
"transcription_test": offline_archive_path["transcription"],
|
127 |
+
"pairs": [offline_archive_path[pair_type] for pair_type in pairs_types],
|
128 |
+
}
|
129 |
+
)
|
130 |
+
]
|
131 |
+
|
132 |
+
split_online = [datasets.SplitGenerator(
|
133 |
+
name="online",
|
134 |
+
gen_kwargs={
|
135 |
+
"audio_files": dl_manager.iter_archive(online_archive_path["data"]),
|
136 |
+
"transcription_keyword": offline_archive_path["transcription"],
|
137 |
+
"transcription_test": online_archive_path["transcription"],
|
138 |
+
"pairs": [online_archive_path[pair_type] for pair_type in pairs_types],
|
139 |
+
}
|
140 |
+
)
|
141 |
+
]
|
142 |
+
|
143 |
+
return split_offline + split_online
|
144 |
+
|
145 |
+
|
146 |
+
def _read_transcription(self, transcription_path):
|
147 |
+
transcription_metadata = {}
|
148 |
+
|
149 |
+
with open(transcription_path, encoding="utf-8") as f:
|
150 |
+
reader = csv.reader(f, delimiter="\t")
|
151 |
+
next(reader, None)
|
152 |
+
|
153 |
+
for row in reader:
|
154 |
+
_, audio_id = os.path.split(row[0])
|
155 |
+
transcription = row[1]
|
156 |
+
transcription_metadata[audio_id] = {
|
157 |
+
"audio_id": audio_id,
|
158 |
+
"transcription": transcription}
|
159 |
+
|
160 |
+
return transcription_metadata
|
161 |
+
|
162 |
+
|
163 |
+
def _generate_examples(self, audio_files, transcription_keyword, transcription_test, pairs):
|
164 |
+
transcription_keyword_metadata = self._read_transcription(transcription_keyword)
|
165 |
+
|
166 |
+
transcription_test_metadata = self._read_transcription(transcription_test)
|
167 |
+
|
168 |
+
pair_metadata = {}
|
169 |
+
for pair in pairs:
|
170 |
+
with open(pair, encoding="utf-8") as f:
|
171 |
+
reader = csv.reader(f, delimiter="\t")
|
172 |
+
next(reader, None)
|
173 |
+
|
174 |
+
for row in reader:
|
175 |
+
_, keyword_id = os.path.split(row[0])
|
176 |
+
_, test_id = os.path.split(row[1])
|
177 |
+
|
178 |
+
if keyword_id not in transcription_keyword_metadata:
|
179 |
+
logger.error("No transcription and audio for keyword %s"%(keyword_id))
|
180 |
+
continue
|
181 |
+
if test_id not in transcription_test_metadata:
|
182 |
+
logger.error("No transcription and audio for test case %s"%(test_id))
|
183 |
+
continue
|
184 |
+
|
185 |
+
if test_id not in pair_metadata:
|
186 |
+
pair_metadata[test_id] = []
|
187 |
+
|
188 |
+
pair_metadata[test_id].append([keyword_id, int(row[-1])])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
|
190 |
id_ = 0
|
191 |
+
for test_path, test_f in audio_files:
|
192 |
+
_, test_id = os.path.split(test_path)
|
193 |
+
if test_id in pair_metadata:
|
194 |
+
test_audio = {"bytes": test_f.read()}
|
195 |
+
for keyword_id, label in pair_metadata[test_id]:
|
196 |
+
yield id_, {
|
197 |
+
"keyword_id": keyword_id,
|
198 |
+
"keyword_transcription": transcription_keyword_metadata[keyword_id]["transcription"],
|
199 |
+
"test_id": test_id,
|
200 |
+
"test_transcription": transcription_test_metadata[test_id]["transcription"],
|
201 |
+
"test_audio": test_audio,
|
202 |
+
"label": label}
|
203 |
+
id_ += 1
|
204 |
+
|