Datasets:
Tasks:
Audio Classification
Sub-tasks:
keyword-spotting
Languages:
English
Size:
10K - 100K
ArXiv:
License:
File size: 9,529 Bytes
5db2b1c fb12e65 5db2b1c c276b7f 5db2b1c c276b7f 5db2b1c c276b7f 5db2b1c c276b7f 5db2b1c c276b7f 5db2b1c fb12e65 72d08a5 fb12e65 5db2b1c fb12e65 5db2b1c 13bba81 fb12e65 5db2b1c 13bba81 fb12e65 5db2b1c 13bba81 fb12e65 5db2b1c fb12e65 5db2b1c fb12e65 5db2b1c 03e513d 5db2b1c fb12e65 5db2b1c fb12e65 72d08a5 fb12e65 5db2b1c fb12e65 c624b60 |
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 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 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# coding=utf-8
# Copyright 2021 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.
"""Speech Commands, an audio dataset of spoken words designed to help train and evaluate keyword spotting systems. """
import textwrap
import datasets
from pathlib import Path
import pandas as pd
_CITATION = """
@article{speechcommandsv2,
author = { {Warden}, P.},
title = "{Speech Commands: A Dataset for Limited-Vocabulary Speech Recognition}",
journal = {ArXiv e-prints},
archivePrefix = "arXiv",
eprint = {1804.03209},
primaryClass = "cs.CL",
keywords = {Computer Science - Computation and Language, Computer Science - Human-Computer Interaction},
year = 2018,
month = apr,
url = {https://arxiv.org/abs/1804.03209},
}
"""
_DESCRIPTION = """
This is a set of one-second .wav audio files, each containing a single spoken
English word or background noise. These words are from a small set of commands, and are spoken by a
variety of different speakers. This data set is designed to help train simple
machine learning models. This dataset is covered in more detail at
[https://arxiv.org/abs/1804.03209](https://arxiv.org/abs/1804.03209).
Version 0.01 of the data set (configuration `"v0.01"`) was released on August 3rd 2017 and contains
64,727 audio files.
In version 0.01 thirty different words were recoded: "Yes", "No", "Up", "Down", "Left",
"Right", "On", "Off", "Stop", "Go", "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
"Bed", "Bird", "Cat", "Dog", "Happy", "House", "Marvin", "Sheila", "Tree", "Wow".
In version 0.02 more words were added: "Backward", "Forward", "Follow", "Learn", "Visual".
In both versions, ten of them are used as commands by convention: "Yes", "No", "Up", "Down", "Left",
"Right", "On", "Off", "Stop", "Go". Other words are considered to be auxiliary (in current implementation
it is marked by `True` value of `"is_unknown"` feature). Their function is to teach a model to distinguish core words
from unrecognized ones.
This version is not yet supported.
The `_silence_` class contains a set of longer audio clips that are either recordings or
a mathematical simulation of noise.
"""
_LICENSE = "Creative Commons BY 4.0 License"
_URL = "https://www.tensorflow.org/datasets/catalog/speech_commands"
_DL_URL = "https://s3.amazonaws.com/datasets.huggingface.co/SpeechCommands/{name}/{name}_{split}.tar.gz"
WORDS = [
"yes",
"no",
"up",
"down",
"left",
"right",
"on",
"off",
"stop",
"go",
]
UNKNOWN_WORDS_V1 = [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"bed",
"bird",
"cat",
"dog",
"happy",
"house",
"marvin",
"sheila",
"tree",
"wow",
]
UNKNOWN_WORDS_V2 = UNKNOWN_WORDS_V1 + [
"backward",
"forward",
"follow",
"learn",
"visual",
]
SILENCE = "_silence_" # background noise
LABELS_V1 = WORDS + UNKNOWN_WORDS_V1 + [SILENCE]
LABELS_V2 = WORDS + UNKNOWN_WORDS_V2 + [SILENCE]
class SpeechCommandsConfig(datasets.BuilderConfig):
"""BuilderConfig for SpeechCommands."""
def __init__(self, labels, **kwargs):
super(SpeechCommandsConfig, self).__init__(**kwargs)
self.labels = labels
class SpeechCommands(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
SpeechCommandsConfig(
name="v0.01",
description=textwrap.dedent(
"""\
Version 0.01 of the SpeechCommands dataset. Contains 30 words
(20 of them are auxiliary) and background noise.
"""
),
labels=LABELS_V1,
version=datasets.Version("0.1.0"),
),
#SpeechCommandsConfig(
# name="v0.02",
# description=textwrap.dedent(
# """\
# Version 0.02 of the SpeechCommands dataset.
# Contains 35 words (25 of them are auxiliary) and background noise.
# """
# ),
# labels=LABELS_V2,
# version=datasets.Version("0.2.0"),
#),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"audio": datasets.Value("string"),
"full_audio": datasets.features.Audio(sampling_rate=16_000),
"label": datasets.ClassLabel(names=self.config.labels),
"is_unknown": datasets.Value("bool"),
"speaker_id": datasets.Value("string"),
"utterance_id": datasets.Value("int8"),
#enriched features:
"label_string": datasets.Value("string"),
"probability": datasets.Value("float64"),
"probability_vector": datasets.Sequence(feature=datasets.Value("float64"), length=31),
"prediction": datasets.ClassLabel(names=self.config.labels),
"prediction_string":datasets.Value("string"),
"embedding_reduced": datasets.Sequence(feature=datasets.Value("float32"), length=2),
}
),
homepage=_URL,
citation=_CITATION,
license=_LICENSE,
version=self.config.version,
)
def _split_generators(self, dl_manager):
archive_paths = dl_manager.download(
{
"train": _DL_URL.format(name=self.config.name, split="train"),
"validation": _DL_URL.format(name=self.config.name, split="validation"),
"test": _DL_URL.format(name=self.config.name, split="test"),
}
)
metadata_paths = dl_manager.download(
{
"train": "data/dataset_audio_train_clipped.parquet.gzip",
"test": "data/dataset_audio_test_clipped.parquet.gzip",
"validation": "data/dataset_audio_validation_clipped.parquet.gzip"
}
)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"archive_path": dl_manager.download_and_extract(archive_paths["train"]),
"metadata": pd.read_parquet(metadata_paths["train"]),
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"archive_path": dl_manager.download_and_extract(archive_paths["validation"]),
"metadata": pd.read_parquet(metadata_paths["validation"]),
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"archive_path": dl_manager.download_and_extract(archive_paths["test"]),
"metadata": pd.read_parquet(metadata_paths["test"]),
},
),
]
def _generate_examples(self, archive_path, metadata):
# HINT: metadata should already be the split-specific metadata
pathlist = Path(archive_path).glob('**/*.wav')
# align metadata and data
pathlist= sorted(pathlist)
for path, row in zip(pathlist, metadata.iterrows()):
# row is a tuple containg an index and a pandas series
pathcomponents = str(path).split("/")
word = pathcomponents[-2]
audio_filename = pathcomponents[-1]
simple_path = word + '/' + audio_filename
is_unknown = False
if word == SILENCE:
speaker_id, utterance_id = None, 0
else: # word is either in WORDS or unknown
if word not in WORDS:
is_unknown = True
# an audio filename looks like `0bac8a71_nohash_0.wav`
speaker_id, _, utterance_id = audio_filename.split(".wav")[0].split("_")
yield simple_path, {
"audio": str(path),
"full_audio": {"path": str(path), "bytes": None},
"label": word,
"is_unknown": is_unknown,
"speaker_id": speaker_id,
"utterance_id": utterance_id,
#enriched features:
"label_string": row[1]["label_string"],
"probability": row[1]["probability"],
"probability_vector": row[1]["probability_vector"],
"prediction": row[1]["prediction"],
"prediction_string": row[1]["prediction_string"],
"embedding_reduced": row[1]["embedding_reduced"]
}
#for debugging, comment out after
#if __name__ == "__main__":
#ds = datasets.load_dataset("speech_commands_enriched.py", 'v0.01', split="test",
#streaming=False)
|