sps44 commited on
Commit
5db2b1c
1 Parent(s): 586550c

first draft extracted archive

Browse files
Files changed (2) hide show
  1. dataset_infos.json +1 -0
  2. speech_commands_enriched.py +243 -0
dataset_infos.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"v0.01": {"description": "\nThis is a set of one-second .wav audio files, each containing a single spoken\nEnglish word or background noise. These words are from a small set of commands, and are spoken by a\nvariety of different speakers. This data set is designed to help train simple\nmachine learning models. This dataset is covered in more detail at\n[https://arxiv.org/abs/1804.03209](https://arxiv.org/abs/1804.03209).\n\nVersion 0.01 of the data set (configuration `\"v0.01\"`) was released on August 3rd 2017 and contains\n64,727 audio files.\n\nIn version 0.01 thirty different words were recoded: \"Yes\", \"No\", \"Up\", \"Down\", \"Left\",\n\"Right\", \"On\", \"Off\", \"Stop\", \"Go\", \"Zero\", \"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\",\n\"Bed\", \"Bird\", \"Cat\", \"Dog\", \"Happy\", \"House\", \"Marvin\", \"Sheila\", \"Tree\", \"Wow\".\n\n\nIn version 0.02 more words were added: \"Backward\", \"Forward\", \"Follow\", \"Learn\", \"Visual\".\n\nIn both versions, ten of them are used as commands by convention: \"Yes\", \"No\", \"Up\", \"Down\", \"Left\",\n\"Right\", \"On\", \"Off\", \"Stop\", \"Go\". Other words are considered to be auxiliary (in current implementation\nit is marked by `True` value of `\"is_unknown\"` feature). Their function is to teach a model to distinguish core words\nfrom unrecognized ones.\n\nThe `_silence_` class contains a set of longer audio clips that are either recordings or\na mathematical simulation of noise.\n\n", "citation": "\n@article{speechcommandsv2,\n author = { {Warden}, P.},\n title = \"{Speech Commands: A Dataset for Limited-Vocabulary Speech Recognition}\",\n journal = {ArXiv e-prints},\n archivePrefix = \"arXiv\",\n eprint = {1804.03209},\n primaryClass = \"cs.CL\",\n keywords = {Computer Science - Computation and Language, Computer Science - Human-Computer Interaction},\n year = 2018,\n month = apr,\n url = {https://arxiv.org/abs/1804.03209},\n}\n", "homepage": "https://www.tensorflow.org/datasets/catalog/speech_commands", "license": "Creative Commons BY 4.0 License", "features": {"file": {"dtype": "string", "id": null, "_type": "Value"}, "audio": {"sampling_rate": 16000, "mono": true, "_storage_dtype": "struct", "id": null, "_type": "Audio"}, "label": {"num_classes": 31, "names": ["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", "_silence_"], "names_file": null, "id": null, "_type": "ClassLabel"}, "is_unknown": {"dtype": "bool", "id": null, "_type": "Value"}, "speaker_id": {"dtype": "string", "id": null, "_type": "Value"}, "utterance_id": {"dtype": "int8", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "speech_commands", "config_name": "v0.01", "version": {"version_str": "0.1.0", "description": null, "major": 0, "minor": 1, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 1626283624, "num_examples": 51093, "dataset_name": "speech_commands"}, "validation": {"name": "validation", "num_bytes": 217204539, "num_examples": 6799, "dataset_name": "speech_commands"}, "test": {"name": "test", "num_bytes": 98979965, "num_examples": 3081, "dataset_name": "speech_commands"}}, "download_checksums": {"https://s3.amazonaws.com/datasets.huggingface.co/SpeechCommands/v0.01/v0.01_train.tar.gz": {"num_bytes": 1176079446, "checksum": "41e4893c0750e576fae0b9c2bb066f6b93b8b7be7be58c60faf037835e7ccb3b"}, "https://s3.amazonaws.com/datasets.huggingface.co/SpeechCommands/v0.01/v0.01_validation.tar.gz": {"num_bytes": 153663590, "checksum": "8f9e1dd79699be3b34552960aa03af1e1c24b4ee014ca28d18d01faca72e1dc0"}, "https://s3.amazonaws.com/datasets.huggingface.co/SpeechCommands/v0.01/v0.01_test.tar.gz": {"num_bytes": 124959719, "checksum": "0ccb217235db6b9e12a3ba3436180bac56d488155ce857614d14584d2b6a3546"}}, "download_size": 1454702755, "post_processing_size": null, "dataset_size": 1942468128, "size_in_bytes": 3397170883}, "v0.02": {"description": "\nThis is a set of one-second .wav audio files, each containing a single spoken\nEnglish word or background noise. These words are from a small set of commands, and are spoken by a\nvariety of different speakers. This data set is designed to help train simple\nmachine learning models. This dataset is covered in more detail at\n[https://arxiv.org/abs/1804.03209](https://arxiv.org/abs/1804.03209).\n\nVersion 0.01 of the data set (configuration `\"v0.01\"`) was released on August 3rd 2017 and contains\n64,727 audio files.\n\nIn version 0.01 thirty different words were recoded: \"Yes\", \"No\", \"Up\", \"Down\", \"Left\",\n\"Right\", \"On\", \"Off\", \"Stop\", \"Go\", \"Zero\", \"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\",\n\"Bed\", \"Bird\", \"Cat\", \"Dog\", \"Happy\", \"House\", \"Marvin\", \"Sheila\", \"Tree\", \"Wow\".\n\n\nIn version 0.02 more words were added: \"Backward\", \"Forward\", \"Follow\", \"Learn\", \"Visual\".\n\nIn both versions, ten of them are used as commands by convention: \"Yes\", \"No\", \"Up\", \"Down\", \"Left\",\n\"Right\", \"On\", \"Off\", \"Stop\", \"Go\". Other words are considered to be auxiliary (in current implementation\nit is marked by `True` value of `\"is_unknown\"` feature). Their function is to teach a model to distinguish core words\nfrom unrecognized ones.\n\nThe `_silence_` class contains a set of longer audio clips that are either recordings or\na mathematical simulation of noise.\n\n", "citation": "\n@article{speechcommandsv2,\n author = { {Warden}, P.},\n title = \"{Speech Commands: A Dataset for Limited-Vocabulary Speech Recognition}\",\n journal = {ArXiv e-prints},\n archivePrefix = \"arXiv\",\n eprint = {1804.03209},\n primaryClass = \"cs.CL\",\n keywords = {Computer Science - Computation and Language, Computer Science - Human-Computer Interaction},\n year = 2018,\n month = apr,\n url = {https://arxiv.org/abs/1804.03209},\n}\n", "homepage": "https://www.tensorflow.org/datasets/catalog/speech_commands", "license": "Creative Commons BY 4.0 License", "features": {"file": {"dtype": "string", "id": null, "_type": "Value"}, "audio": {"sampling_rate": 16000, "mono": true, "_storage_dtype": "struct", "id": null, "_type": "Audio"}, "label": {"num_classes": 36, "names": ["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", "backward", "forward", "follow", "learn", "visual", "_silence_"], "names_file": null, "id": null, "_type": "ClassLabel"}, "is_unknown": {"dtype": "bool", "id": null, "_type": "Value"}, "speaker_id": {"dtype": "string", "id": null, "_type": "Value"}, "utterance_id": {"dtype": "int8", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "speech_commands", "config_name": "v0.02", "version": {"version_str": "0.2.0", "description": null, "major": 0, "minor": 2, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 2684381672, "num_examples": 84848, "dataset_name": "speech_commands"}, "validation": {"name": "validation", "num_bytes": 316435178, "num_examples": 9982, "dataset_name": "speech_commands"}, "test": {"name": "test", "num_bytes": 157096106, "num_examples": 4890, "dataset_name": "speech_commands"}}, "download_checksums": {"https://s3.amazonaws.com/datasets.huggingface.co/SpeechCommands/v0.02/v0.02_train.tar.gz": {"num_bytes": 1944462432, "checksum": "acfc1a9e5f020ef5d20f13bb5c1035dcc19a3cc6d5fd1fe775d99814ce840399"}, "https://s3.amazonaws.com/datasets.huggingface.co/SpeechCommands/v0.02/v0.02_validation.tar.gz": {"num_bytes": 229117586, "checksum": "868bdecd3dc12276ee55d2aeca5b1f02d913d6f17875181c1bf9d465fa2f7be1"}, "https://s3.amazonaws.com/datasets.huggingface.co/SpeechCommands/v0.02/v0.02_test.tar.gz": {"num_bytes": 112395851, "checksum": "45aedb39cb2c9f03e098a8d5c98350d6d8473c432ad4558fce26c6feb478a812"}}, "download_size": 2285975869, "post_processing_size": null, "dataset_size": 3157912956, "size_in_bytes": 5443888825}}
speech_commands_enriched.py ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2021 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """Speech Commands, an audio dataset of spoken words designed to help train and evaluate keyword spotting systems. """
17
+
18
+
19
+ import textwrap
20
+
21
+ import datasets
22
+
23
+ from pathlib import Path
24
+
25
+
26
+ _CITATION = """
27
+ @article{speechcommandsv2,
28
+ author = { {Warden}, P.},
29
+ title = "{Speech Commands: A Dataset for Limited-Vocabulary Speech Recognition}",
30
+ journal = {ArXiv e-prints},
31
+ archivePrefix = "arXiv",
32
+ eprint = {1804.03209},
33
+ primaryClass = "cs.CL",
34
+ keywords = {Computer Science - Computation and Language, Computer Science - Human-Computer Interaction},
35
+ year = 2018,
36
+ month = apr,
37
+ url = {https://arxiv.org/abs/1804.03209},
38
+ }
39
+ """
40
+
41
+ _DESCRIPTION = """
42
+ This is a set of one-second .wav audio files, each containing a single spoken
43
+ English word or background noise. These words are from a small set of commands, and are spoken by a
44
+ variety of different speakers. This data set is designed to help train simple
45
+ machine learning models. This dataset is covered in more detail at
46
+ [https://arxiv.org/abs/1804.03209](https://arxiv.org/abs/1804.03209).
47
+
48
+ Version 0.01 of the data set (configuration `"v0.01"`) was released on August 3rd 2017 and contains
49
+ 64,727 audio files.
50
+
51
+ In version 0.01 thirty different words were recoded: "Yes", "No", "Up", "Down", "Left",
52
+ "Right", "On", "Off", "Stop", "Go", "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
53
+ "Bed", "Bird", "Cat", "Dog", "Happy", "House", "Marvin", "Sheila", "Tree", "Wow".
54
+
55
+
56
+ In version 0.02 more words were added: "Backward", "Forward", "Follow", "Learn", "Visual".
57
+
58
+ In both versions, ten of them are used as commands by convention: "Yes", "No", "Up", "Down", "Left",
59
+ "Right", "On", "Off", "Stop", "Go". Other words are considered to be auxiliary (in current implementation
60
+ it is marked by `True` value of `"is_unknown"` feature). Their function is to teach a model to distinguish core words
61
+ from unrecognized ones.
62
+
63
+ The `_silence_` class contains a set of longer audio clips that are either recordings or
64
+ a mathematical simulation of noise.
65
+
66
+ """
67
+
68
+ _LICENSE = "Creative Commons BY 4.0 License"
69
+
70
+ _URL = "https://www.tensorflow.org/datasets/catalog/speech_commands"
71
+
72
+ _DL_URL = "https://s3.amazonaws.com/datasets.huggingface.co/SpeechCommands/{name}/{name}_{split}.tar.gz"
73
+
74
+ WORDS = [
75
+ "yes",
76
+ "no",
77
+ "up",
78
+ "down",
79
+ "left",
80
+ "right",
81
+ "on",
82
+ "off",
83
+ "stop",
84
+ "go",
85
+ ]
86
+
87
+ UNKNOWN_WORDS_V1 = [
88
+ "zero",
89
+ "one",
90
+ "two",
91
+ "three",
92
+ "four",
93
+ "five",
94
+ "six",
95
+ "seven",
96
+ "eight",
97
+ "nine",
98
+ "bed",
99
+ "bird",
100
+ "cat",
101
+ "dog",
102
+ "happy",
103
+ "house",
104
+ "marvin",
105
+ "sheila",
106
+ "tree",
107
+ "wow",
108
+ ]
109
+
110
+ UNKNOWN_WORDS_V2 = UNKNOWN_WORDS_V1 + [
111
+ "backward",
112
+ "forward",
113
+ "follow",
114
+ "learn",
115
+ "visual",
116
+ ]
117
+
118
+ SILENCE = "_silence_" # background noise
119
+ LABELS_V1 = WORDS + UNKNOWN_WORDS_V1 + [SILENCE]
120
+ LABELS_V2 = WORDS + UNKNOWN_WORDS_V2 + [SILENCE]
121
+
122
+
123
+ class SpeechCommandsConfig(datasets.BuilderConfig):
124
+ """BuilderConfig for SpeechCommands."""
125
+
126
+ def __init__(self, labels, **kwargs):
127
+ super(SpeechCommandsConfig, self).__init__(**kwargs)
128
+ self.labels = labels
129
+
130
+
131
+ class SpeechCommands(datasets.GeneratorBasedBuilder):
132
+ BUILDER_CONFIGS = [
133
+ SpeechCommandsConfig(
134
+ name="v0.01",
135
+ description=textwrap.dedent(
136
+ """\
137
+ Version 0.01 of the SpeechCommands dataset. Contains 30 words
138
+ (20 of them are auxiliary) and background noise.
139
+ """
140
+ ),
141
+ labels=LABELS_V1,
142
+ version=datasets.Version("0.1.0"),
143
+ ),
144
+ SpeechCommandsConfig(
145
+ name="v0.02",
146
+ description=textwrap.dedent(
147
+ """\
148
+ Version 0.02 of the SpeechCommands dataset.
149
+ Contains 35 words (25 of them are auxiliary) and background noise.
150
+ """
151
+ ),
152
+ labels=LABELS_V2,
153
+ version=datasets.Version("0.2.0"),
154
+ ),
155
+ ]
156
+
157
+ def _info(self):
158
+ return datasets.DatasetInfo(
159
+ description=_DESCRIPTION,
160
+ features=datasets.Features(
161
+ {
162
+ "audio": datasets.Value("string"),
163
+ "full_audio": datasets.features.Audio(sampling_rate=16_000),
164
+ "label": datasets.ClassLabel(names=self.config.labels),
165
+ "is_unknown": datasets.Value("bool"),
166
+ "speaker_id": datasets.Value("string"),
167
+ "utterance_id": datasets.Value("int8"),
168
+ }
169
+ ),
170
+ homepage=_URL,
171
+ citation=_CITATION,
172
+ license=_LICENSE,
173
+ version=self.config.version,
174
+ )
175
+
176
+ def _split_generators(self, dl_manager):
177
+
178
+ archive_paths = dl_manager.download(
179
+ {
180
+ "train": _DL_URL.format(name=self.config.name, split="train"),
181
+ "validation": _DL_URL.format(name=self.config.name, split="validation"),
182
+ "test": _DL_URL.format(name=self.config.name, split="test"),
183
+ }
184
+ )
185
+
186
+ return [
187
+ datasets.SplitGenerator(
188
+ name=datasets.Split.TRAIN,
189
+ gen_kwargs={
190
+ "archive_path": dl_manager.download_and_extract(archive_paths["train"]),
191
+ },
192
+ ),
193
+ datasets.SplitGenerator(
194
+ name=datasets.Split.VALIDATION,
195
+ gen_kwargs={
196
+ "archive_path": dl_manager.download_and_extract(archive_paths["validation"]),
197
+ },
198
+ ),
199
+ datasets.SplitGenerator(
200
+ name=datasets.Split.TEST,
201
+ gen_kwargs={
202
+ "archive_path": dl_manager.download_and_extract(archive_paths["test"]),
203
+ },
204
+ ),
205
+ ]
206
+
207
+ def _generate_examples(self, archive_path):
208
+
209
+
210
+
211
+ pathlist = Path(archive_path).glob('**/*.wav')
212
+
213
+ for path in pathlist:
214
+
215
+ pathcomponents = str(path).split("/")
216
+ word = pathcomponents[-2]
217
+ audio_filename = pathcomponents[-1]
218
+
219
+ simple_path = word + '/' + audio_filename
220
+
221
+ is_unknown = False
222
+
223
+ if word == SILENCE:
224
+ speaker_id, utterance_id = None, 0
225
+
226
+ else: # word is either in WORDS or unknown
227
+ if word not in WORDS:
228
+ is_unknown = True
229
+ # an audio filename looks like `0bac8a71_nohash_0.wav`
230
+ speaker_id, _, utterance_id = audio_filename.split(".wav")[0].split("_")
231
+
232
+ yield simple_path, {
233
+ "audio": str(path),
234
+ "full_audio": {"path": str(path), "bytes": None},
235
+ "label": word,
236
+ "is_unknown": is_unknown,
237
+ "speaker_id": speaker_id,
238
+ "utterance_id": utterance_id,
239
+ }
240
+
241
+ #for debugging
242
+ if __name__ == "__main__":
243
+ ds = datasets.load_dataset("speech_commands_enriched.py", 'v0.01', split="train", streaming=False)