Isma commited on
Commit
43afcb1
1 Parent(s): 6063fac

Upload librispeech_tiny_creation.ipynb

Browse files

The code that was used to extract this tiny dataset from the librispeech dataset.

Files changed (1) hide show
  1. librispeech_tiny_creation.ipynb +374 -0
librispeech_tiny_creation.ipynb ADDED
@@ -0,0 +1,374 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 5,
6
+ "id": "c4f101d6-ca08-4236-9034-c86968fc7830",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "Found cached dataset librispeech_asr (/home/jupyter/.cache/huggingface/datasets/librispeech_asr/all/2.1.0/cff5df6e7955c80a67f80e27e7e655de71c689e2d2364bece785b972acb37fe7)\n"
14
+ ]
15
+ },
16
+ {
17
+ "data": {
18
+ "application/vnd.jupyter.widget-view+json": {
19
+ "model_id": "8c87424fb2904b1894800b3ec3de48ec",
20
+ "version_major": 2,
21
+ "version_minor": 0
22
+ },
23
+ "text/plain": [
24
+ " 0%| | 0/7 [00:00<?, ?it/s]"
25
+ ]
26
+ },
27
+ "metadata": {},
28
+ "output_type": "display_data"
29
+ },
30
+ {
31
+ "name": "stderr",
32
+ "output_type": "stream",
33
+ "text": [
34
+ "Loading cached shuffled indices for dataset at /home/jupyter/.cache/huggingface/datasets/librispeech_asr/all/2.1.0/cff5df6e7955c80a67f80e27e7e655de71c689e2d2364bece785b972acb37fe7/cache-c0ea02798a773cf7.arrow\n"
35
+ ]
36
+ }
37
+ ],
38
+ "source": [
39
+ "# load the dataset\n",
40
+ "from datasets import load_dataset, DatasetDict\n",
41
+ "import torch \n",
42
+ "\n",
43
+ "# fix a random seed to make sure different run give the same dataset\n",
44
+ "seed = 17\n",
45
+ "\n",
46
+ "# load the librispeech dataset and shuffle it \n",
47
+ "dataset = load_dataset(\"librispeech_asr\",\"all\")['train.clean.100']\n",
48
+ "dataset = dataset.shuffle(seed=seed)"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "code",
53
+ "execution_count": 6,
54
+ "id": "c5153afc-4ce3-45a6-9480-a33c636c7706",
55
+ "metadata": {},
56
+ "outputs": [],
57
+ "source": [
58
+ "# select enough element to get elements to get to 20 minutes\n",
59
+ "i_10mn = 0\n",
60
+ "duration = 0 \n",
61
+ "while duration < 600: # until we reach 1200s \n",
62
+ " duration += dataset[i_10mn]['audio']['array'].shape[0]/dataset[i_10mn]['audio']['sampling_rate']\n",
63
+ " i_10mn += 1\n",
64
+ "\n",
65
+ "librispeech_10mn = dataset.select(range(i_10mn)) \n",
66
+ "\n",
67
+ "# select elements on the following to get 1h\n",
68
+ "i_1h = i_10mn\n",
69
+ "duration=0\n",
70
+ "while duration < 3600: # until we reach 1200s \n",
71
+ " duration += dataset[i_1h]['audio']['array'].shape[0]/dataset[i_1h]['audio']['sampling_rate']\n",
72
+ " i_1h += 1\n",
73
+ " \n",
74
+ "librispeech_1h = dataset.select(range(i_10mn,i_1h))\n",
75
+ "\n",
76
+ "# select elements to get to 2h\n",
77
+ "i_2h = i_1h\n",
78
+ "duration = 0\n",
79
+ "while duration < 7200: # until we reach 1200s \n",
80
+ " duration += dataset[i_2h]['audio']['array'].shape[0]/dataset[i_2h]['audio']['sampling_rate']\n",
81
+ " i_2h += 1\n",
82
+ " \n",
83
+ "librispeech_2h = dataset.select(range(i_1h,i_2h))\n",
84
+ "\n",
85
+ "# put them together\n",
86
+ "librispeech_tiny = DatasetDict({'10mn':librispeech_10mn,\n",
87
+ " '1h': librispeech_1h,\n",
88
+ " '2h': librispeech_2h\n",
89
+ " }\n",
90
+ " )\n",
91
+ "\n",
92
+ "\n",
93
+ "\n"
94
+ ]
95
+ },
96
+ {
97
+ "cell_type": "code",
98
+ "execution_count": 7,
99
+ "id": "5cc28e11-803c-4760-9005-516157eb8945",
100
+ "metadata": {},
101
+ "outputs": [
102
+ {
103
+ "data": {
104
+ "text/plain": [
105
+ "DatasetDict({\n",
106
+ " 10mn: Dataset({\n",
107
+ " features: ['file', 'audio', 'text', 'speaker_id', 'chapter_id', 'id'],\n",
108
+ " num_rows: 50\n",
109
+ " })\n",
110
+ " 1h: Dataset({\n",
111
+ " features: ['file', 'audio', 'text', 'speaker_id', 'chapter_id', 'id'],\n",
112
+ " num_rows: 284\n",
113
+ " })\n",
114
+ " 2h: Dataset({\n",
115
+ " features: ['file', 'audio', 'text', 'speaker_id', 'chapter_id', 'id'],\n",
116
+ " num_rows: 576\n",
117
+ " })\n",
118
+ "})"
119
+ ]
120
+ },
121
+ "execution_count": 7,
122
+ "metadata": {},
123
+ "output_type": "execute_result"
124
+ }
125
+ ],
126
+ "source": [
127
+ "librispeech_tiny"
128
+ ]
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "execution_count": 11,
133
+ "id": "e08cddc6-364c-45cf-ac7b-d2a4d0ec8e65",
134
+ "metadata": {},
135
+ "outputs": [
136
+ {
137
+ "name": "stderr",
138
+ "output_type": "stream",
139
+ "text": [
140
+ "Pushing split 10mn to the Hub.\n"
141
+ ]
142
+ },
143
+ {
144
+ "data": {
145
+ "application/vnd.jupyter.widget-view+json": {
146
+ "model_id": "d2135c4ef2af4b72803dddaff88cb092",
147
+ "version_major": 2,
148
+ "version_minor": 0
149
+ },
150
+ "text/plain": [
151
+ " 0%| | 0/1 [00:00<?, ?ba/s]"
152
+ ]
153
+ },
154
+ "metadata": {},
155
+ "output_type": "display_data"
156
+ },
157
+ {
158
+ "data": {
159
+ "application/vnd.jupyter.widget-view+json": {
160
+ "model_id": "d42ce27a96f448cc924703bfe0b30065",
161
+ "version_major": 2,
162
+ "version_minor": 0
163
+ },
164
+ "text/plain": [
165
+ "Pushing dataset shards to the dataset hub: 0%| | 0/1 [00:00<?, ?it/s]"
166
+ ]
167
+ },
168
+ "metadata": {},
169
+ "output_type": "display_data"
170
+ },
171
+ {
172
+ "name": "stderr",
173
+ "output_type": "stream",
174
+ "text": [
175
+ "Pushing split 1h to the Hub.\n"
176
+ ]
177
+ },
178
+ {
179
+ "data": {
180
+ "application/vnd.jupyter.widget-view+json": {
181
+ "model_id": "57a8cb106ff14b1fb186c3e86122f497",
182
+ "version_major": 2,
183
+ "version_minor": 0
184
+ },
185
+ "text/plain": [
186
+ " 0%| | 0/1 [00:00<?, ?ba/s]"
187
+ ]
188
+ },
189
+ "metadata": {},
190
+ "output_type": "display_data"
191
+ },
192
+ {
193
+ "data": {
194
+ "application/vnd.jupyter.widget-view+json": {
195
+ "model_id": "a3c8ea385d1a46108db9a51144e82f66",
196
+ "version_major": 2,
197
+ "version_minor": 0
198
+ },
199
+ "text/plain": [
200
+ "Pushing dataset shards to the dataset hub: 0%| | 0/1 [00:00<?, ?it/s]"
201
+ ]
202
+ },
203
+ "metadata": {},
204
+ "output_type": "display_data"
205
+ },
206
+ {
207
+ "name": "stderr",
208
+ "output_type": "stream",
209
+ "text": [
210
+ "Pushing split 2h to the Hub.\n"
211
+ ]
212
+ },
213
+ {
214
+ "data": {
215
+ "application/vnd.jupyter.widget-view+json": {
216
+ "model_id": "33a0b8ce30d04b5c87e72efbee8e40d1",
217
+ "version_major": 2,
218
+ "version_minor": 0
219
+ },
220
+ "text/plain": [
221
+ " 0%| | 0/1 [00:00<?, ?ba/s]"
222
+ ]
223
+ },
224
+ "metadata": {},
225
+ "output_type": "display_data"
226
+ },
227
+ {
228
+ "data": {
229
+ "application/vnd.jupyter.widget-view+json": {
230
+ "model_id": "1ac0a669b0e54dffae68dce597d7486b",
231
+ "version_major": 2,
232
+ "version_minor": 0
233
+ },
234
+ "text/plain": [
235
+ "Pushing dataset shards to the dataset hub: 0%| | 0/1 [00:00<?, ?it/s]"
236
+ ]
237
+ },
238
+ "metadata": {},
239
+ "output_type": "display_data"
240
+ }
241
+ ],
242
+ "source": [
243
+ "librispeech_tiny.push_to_hub('Isma/librispeech_tiny')"
244
+ ]
245
+ },
246
+ {
247
+ "cell_type": "code",
248
+ "execution_count": 8,
249
+ "id": "d938122a-3c6b-4585-951a-6e9aac77f804",
250
+ "metadata": {},
251
+ "outputs": [
252
+ {
253
+ "data": {
254
+ "text/plain": [
255
+ "(50, 334, 910, 7208.405187500002)"
256
+ ]
257
+ },
258
+ "execution_count": 8,
259
+ "metadata": {},
260
+ "output_type": "execute_result"
261
+ }
262
+ ],
263
+ "source": [
264
+ "#i_10mn,i_1h, i_2h, duration "
265
+ ]
266
+ },
267
+ {
268
+ "cell_type": "code",
269
+ "execution_count": null,
270
+ "id": "df7b7a37-1b07-4454-bb2e-f381b938ed41",
271
+ "metadata": {},
272
+ "outputs": [],
273
+ "source": []
274
+ },
275
+ {
276
+ "cell_type": "code",
277
+ "execution_count": 10,
278
+ "id": "71ae1e94-4d66-41db-9dd2-f54eaed61187",
279
+ "metadata": {},
280
+ "outputs": [
281
+ {
282
+ "data": {
283
+ "text/plain": [
284
+ "dict_keys(['path', 'array', 'sampling_rate'])"
285
+ ]
286
+ },
287
+ "execution_count": 10,
288
+ "metadata": {},
289
+ "output_type": "execute_result"
290
+ }
291
+ ],
292
+ "source": [
293
+ "#dataset[0]['audio'].keys()"
294
+ ]
295
+ },
296
+ {
297
+ "cell_type": "code",
298
+ "execution_count": 5,
299
+ "id": "7a934fa2-8273-496b-b20c-9431cc965181",
300
+ "metadata": {},
301
+ "outputs": [
302
+ {
303
+ "data": {
304
+ "text/plain": [
305
+ "6.1"
306
+ ]
307
+ },
308
+ "execution_count": 5,
309
+ "metadata": {},
310
+ "output_type": "execute_result"
311
+ }
312
+ ],
313
+ "source": []
314
+ },
315
+ {
316
+ "cell_type": "code",
317
+ "execution_count": 21,
318
+ "id": "65d22ed9-f920-48eb-8ea4-670111c5dd47",
319
+ "metadata": {},
320
+ "outputs": [
321
+ {
322
+ "data": {
323
+ "text/plain": [
324
+ "(10, 127)"
325
+ ]
326
+ },
327
+ "execution_count": 21,
328
+ "metadata": {},
329
+ "output_type": "execute_result"
330
+ }
331
+ ],
332
+ "source": [
333
+ "i_1h = i_10mn\n",
334
+ "i_1h = 10\n",
335
+ "i_1h, i_10mn"
336
+ ]
337
+ },
338
+ {
339
+ "cell_type": "code",
340
+ "execution_count": null,
341
+ "id": "99bfbd13-93ca-4d64-bfe5-e6b883b24cef",
342
+ "metadata": {},
343
+ "outputs": [],
344
+ "source": []
345
+ }
346
+ ],
347
+ "metadata": {
348
+ "environment": {
349
+ "kernel": "python3",
350
+ "name": "common-cu110.m102",
351
+ "type": "gcloud",
352
+ "uri": "gcr.io/deeplearning-platform-release/base-cu110:m102"
353
+ },
354
+ "kernelspec": {
355
+ "display_name": "Python 3",
356
+ "language": "python",
357
+ "name": "python3"
358
+ },
359
+ "language_info": {
360
+ "codemirror_mode": {
361
+ "name": "ipython",
362
+ "version": 3
363
+ },
364
+ "file_extension": ".py",
365
+ "mimetype": "text/x-python",
366
+ "name": "python",
367
+ "nbconvert_exporter": "python",
368
+ "pygments_lexer": "ipython3",
369
+ "version": "3.7.12"
370
+ }
371
+ },
372
+ "nbformat": 4,
373
+ "nbformat_minor": 5
374
+ }