ivangtorre commited on
Commit
8c033c4
1 Parent(s): fd0d156

changing and deleting files

Browse files
Files changed (1) hide show
  1. Generate_metadata.ipynb +0 -883
Generate_metadata.ipynb DELETED
@@ -1,883 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "id": "91b21cf6",
6
- "metadata": {},
7
- "source": [
8
- "## Generate the datasets for uploading"
9
- ]
10
- },
11
- {
12
- "cell_type": "code",
13
- "execution_count": null,
14
- "id": "e1a3d25b",
15
- "metadata": {},
16
- "outputs": [],
17
- "source": []
18
- },
19
- {
20
- "cell_type": "code",
21
- "execution_count": 21,
22
- "id": "aa925968",
23
- "metadata": {
24
- "scrolled": true
25
- },
26
- "outputs": [
27
- {
28
- "name": "stdout",
29
- "output_type": "stream",
30
- "text": [
31
- "[]\n"
32
- ]
33
- },
34
- {
35
- "data": {
36
- "application/vnd.jupyter.widget-view+json": {
37
- "model_id": "86aedd302b3041d9b4bf80a3c60c096a",
38
- "version_major": 2,
39
- "version_minor": 0
40
- },
41
- "text/plain": [
42
- "Uploading the dataset shards: 0%| | 0/1 [00:00<?, ?it/s]"
43
- ]
44
- },
45
- "metadata": {},
46
- "output_type": "display_data"
47
- },
48
- {
49
- "data": {
50
- "application/vnd.jupyter.widget-view+json": {
51
- "model_id": "d40686210f1b49cf9a2b980964f32c34",
52
- "version_major": 2,
53
- "version_minor": 0
54
- },
55
- "text/plain": [
56
- "Map: 0%| | 0/1097 [00:00<?, ? examples/s]"
57
- ]
58
- },
59
- "metadata": {},
60
- "output_type": "display_data"
61
- },
62
- {
63
- "data": {
64
- "application/vnd.jupyter.widget-view+json": {
65
- "model_id": "6e86ed4b25894e37837cdb6cb46e662a",
66
- "version_major": 2,
67
- "version_minor": 0
68
- },
69
- "text/plain": [
70
- "Creating parquet from Arrow format: 0%| | 0/11 [00:00<?, ?ba/s]"
71
- ]
72
- },
73
- "metadata": {},
74
- "output_type": "display_data"
75
- },
76
- {
77
- "data": {
78
- "application/vnd.jupyter.widget-view+json": {
79
- "model_id": "d138c6b6f3b548298986710d9dbea010",
80
- "version_major": 2,
81
- "version_minor": 0
82
- },
83
- "text/plain": [
84
- "README.md: 0%| | 0.00/1.64k [00:00<?, ?B/s]"
85
- ]
86
- },
87
- "metadata": {},
88
- "output_type": "display_data"
89
- },
90
- {
91
- "name": "stdout",
92
- "output_type": "stream",
93
- "text": [
94
- "[]\n"
95
- ]
96
- },
97
- {
98
- "data": {
99
- "application/vnd.jupyter.widget-view+json": {
100
- "model_id": "41c0e3b2a72f4ce690a5d068ad6ee76e",
101
- "version_major": 2,
102
- "version_minor": 0
103
- },
104
- "text/plain": [
105
- "Uploading the dataset shards: 0%| | 0/1 [00:00<?, ?it/s]"
106
- ]
107
- },
108
- "metadata": {},
109
- "output_type": "display_data"
110
- },
111
- {
112
- "data": {
113
- "application/vnd.jupyter.widget-view+json": {
114
- "model_id": "c4c9e9d1a0c64e728527636022468fb0",
115
- "version_major": 2,
116
- "version_minor": 0
117
- },
118
- "text/plain": [
119
- "Map: 0%| | 0/1097 [00:00<?, ? examples/s]"
120
- ]
121
- },
122
- "metadata": {},
123
- "output_type": "display_data"
124
- },
125
- {
126
- "data": {
127
- "application/vnd.jupyter.widget-view+json": {
128
- "model_id": "de8c8d8db3704cbe9e86266166e898fa",
129
- "version_major": 2,
130
- "version_minor": 0
131
- },
132
- "text/plain": [
133
- "Creating parquet from Arrow format: 0%| | 0/11 [00:00<?, ?ba/s]"
134
- ]
135
- },
136
- "metadata": {},
137
- "output_type": "display_data"
138
- },
139
- {
140
- "data": {
141
- "application/vnd.jupyter.widget-view+json": {
142
- "model_id": "30139cf5070d40d69db2bc1aa691e422",
143
- "version_major": 2,
144
- "version_minor": 0
145
- },
146
- "text/plain": [
147
- "README.md: 0%| | 0.00/1.64k [00:00<?, ?B/s]"
148
- ]
149
- },
150
- "metadata": {},
151
- "output_type": "display_data"
152
- },
153
- {
154
- "name": "stdout",
155
- "output_type": "stream",
156
- "text": [
157
- "[]\n"
158
- ]
159
- },
160
- {
161
- "data": {
162
- "application/vnd.jupyter.widget-view+json": {
163
- "model_id": "91e76dd77c394f10a6316e2cbc738f53",
164
- "version_major": 2,
165
- "version_minor": 0
166
- },
167
- "text/plain": [
168
- "Uploading the dataset shards: 0%| | 0/1 [00:00<?, ?it/s]"
169
- ]
170
- },
171
- "metadata": {},
172
- "output_type": "display_data"
173
- },
174
- {
175
- "data": {
176
- "application/vnd.jupyter.widget-view+json": {
177
- "model_id": "dd557f750be248b8900132ec09bd3ea9",
178
- "version_major": 2,
179
- "version_minor": 0
180
- },
181
- "text/plain": [
182
- "Map: 0%| | 0/1097 [00:00<?, ? examples/s]"
183
- ]
184
- },
185
- "metadata": {},
186
- "output_type": "display_data"
187
- },
188
- {
189
- "data": {
190
- "application/vnd.jupyter.widget-view+json": {
191
- "model_id": "82d08a53de1f42f8a8e2a98686f15e02",
192
- "version_major": 2,
193
- "version_minor": 0
194
- },
195
- "text/plain": [
196
- "Creating parquet from Arrow format: 0%| | 0/11 [00:00<?, ?ba/s]"
197
- ]
198
- },
199
- "metadata": {},
200
- "output_type": "display_data"
201
- },
202
- {
203
- "data": {
204
- "application/vnd.jupyter.widget-view+json": {
205
- "model_id": "0c86ca04ca6d46b7a4637153831843c6",
206
- "version_major": 2,
207
- "version_minor": 0
208
- },
209
- "text/plain": [
210
- "README.md: 0%| | 0.00/1.75k [00:00<?, ?B/s]"
211
- ]
212
- },
213
- "metadata": {},
214
- "output_type": "display_data"
215
- },
216
- {
217
- "name": "stdout",
218
- "output_type": "stream",
219
- "text": [
220
- "[]\n"
221
- ]
222
- },
223
- {
224
- "data": {
225
- "application/vnd.jupyter.widget-view+json": {
226
- "model_id": "1105fc397b7942569e2b6e7263dadb3e",
227
- "version_major": 2,
228
- "version_minor": 0
229
- },
230
- "text/plain": [
231
- "Uploading the dataset shards: 0%| | 0/1 [00:00<?, ?it/s]"
232
- ]
233
- },
234
- "metadata": {},
235
- "output_type": "display_data"
236
- },
237
- {
238
- "data": {
239
- "application/vnd.jupyter.widget-view+json": {
240
- "model_id": "b2464a4420284e2fa43352d21cc0849d",
241
- "version_major": 2,
242
- "version_minor": 0
243
- },
244
- "text/plain": [
245
- "Map: 0%| | 0/1097 [00:00<?, ? examples/s]"
246
- ]
247
- },
248
- "metadata": {},
249
- "output_type": "display_data"
250
- },
251
- {
252
- "data": {
253
- "application/vnd.jupyter.widget-view+json": {
254
- "model_id": "b4b5a5308c584bfeb9933074e70cfa0a",
255
- "version_major": 2,
256
- "version_minor": 0
257
- },
258
- "text/plain": [
259
- "Creating parquet from Arrow format: 0%| | 0/11 [00:00<?, ?ba/s]"
260
- ]
261
- },
262
- "metadata": {},
263
- "output_type": "display_data"
264
- },
265
- {
266
- "data": {
267
- "application/vnd.jupyter.widget-view+json": {
268
- "model_id": "eefe4a691e4e4d1db3f8ea7db47b068e",
269
- "version_major": 2,
270
- "version_minor": 0
271
- },
272
- "text/plain": [
273
- "README.md: 0%| | 0.00/2.22k [00:00<?, ?B/s]"
274
- ]
275
- },
276
- "metadata": {},
277
- "output_type": "display_data"
278
- },
279
- {
280
- "name": "stdout",
281
- "output_type": "stream",
282
- "text": [
283
- "[]\n"
284
- ]
285
- },
286
- {
287
- "data": {
288
- "application/vnd.jupyter.widget-view+json": {
289
- "model_id": "75a9f81c1ee843c397590f4d156df530",
290
- "version_major": 2,
291
- "version_minor": 0
292
- },
293
- "text/plain": [
294
- "Uploading the dataset shards: 0%| | 0/1 [00:00<?, ?it/s]"
295
- ]
296
- },
297
- "metadata": {},
298
- "output_type": "display_data"
299
- },
300
- {
301
- "data": {
302
- "application/vnd.jupyter.widget-view+json": {
303
- "model_id": "ec3e0856e7074218a23062cf1f4a84b9",
304
- "version_major": 2,
305
- "version_minor": 0
306
- },
307
- "text/plain": [
308
- "Map: 0%| | 0/1097 [00:00<?, ? examples/s]"
309
- ]
310
- },
311
- "metadata": {},
312
- "output_type": "display_data"
313
- },
314
- {
315
- "data": {
316
- "application/vnd.jupyter.widget-view+json": {
317
- "model_id": "f4db44eb772642daa5fb9533ce793085",
318
- "version_major": 2,
319
- "version_minor": 0
320
- },
321
- "text/plain": [
322
- "Creating parquet from Arrow format: 0%| | 0/11 [00:00<?, ?ba/s]"
323
- ]
324
- },
325
- "metadata": {},
326
- "output_type": "display_data"
327
- },
328
- {
329
- "data": {
330
- "application/vnd.jupyter.widget-view+json": {
331
- "model_id": "8f455a25b8ec4686b36569e323b93e3f",
332
- "version_major": 2,
333
- "version_minor": 0
334
- },
335
- "text/plain": [
336
- "README.md: 0%| | 0.00/2.32k [00:00<?, ?B/s]"
337
- ]
338
- },
339
- "metadata": {},
340
- "output_type": "display_data"
341
- },
342
- {
343
- "name": "stdout",
344
- "output_type": "stream",
345
- "text": [
346
- "[]\n"
347
- ]
348
- },
349
- {
350
- "data": {
351
- "application/vnd.jupyter.widget-view+json": {
352
- "model_id": "780547210b7e4db588220b112c7958f7",
353
- "version_major": 2,
354
- "version_minor": 0
355
- },
356
- "text/plain": [
357
- "Uploading the dataset shards: 0%| | 0/1 [00:00<?, ?it/s]"
358
- ]
359
- },
360
- "metadata": {},
361
- "output_type": "display_data"
362
- },
363
- {
364
- "data": {
365
- "application/vnd.jupyter.widget-view+json": {
366
- "model_id": "1d7eaf59c4eb4bcb9aab6dd38fd0f101",
367
- "version_major": 2,
368
- "version_minor": 0
369
- },
370
- "text/plain": [
371
- "Map: 0%| | 0/1097 [00:00<?, ? examples/s]"
372
- ]
373
- },
374
- "metadata": {},
375
- "output_type": "display_data"
376
- },
377
- {
378
- "data": {
379
- "application/vnd.jupyter.widget-view+json": {
380
- "model_id": "7ebec41677a04747ae02d1645a19bf8d",
381
- "version_major": 2,
382
- "version_minor": 0
383
- },
384
- "text/plain": [
385
- "Creating parquet from Arrow format: 0%| | 0/11 [00:00<?, ?ba/s]"
386
- ]
387
- },
388
- "metadata": {},
389
- "output_type": "display_data"
390
- },
391
- {
392
- "data": {
393
- "application/vnd.jupyter.widget-view+json": {
394
- "model_id": "4ed3f65de03c48f488ca3f518d063d0d",
395
- "version_major": 2,
396
- "version_minor": 0
397
- },
398
- "text/plain": [
399
- "README.md: 0%| | 0.00/2.80k [00:00<?, ?B/s]"
400
- ]
401
- },
402
- "metadata": {},
403
- "output_type": "display_data"
404
- },
405
- {
406
- "name": "stdout",
407
- "output_type": "stream",
408
- "text": [
409
- "[]\n"
410
- ]
411
- },
412
- {
413
- "data": {
414
- "application/vnd.jupyter.widget-view+json": {
415
- "model_id": "d888ccc2841c4ed8a70e94562e404c34",
416
- "version_major": 2,
417
- "version_minor": 0
418
- },
419
- "text/plain": [
420
- "Uploading the dataset shards: 0%| | 0/1 [00:00<?, ?it/s]"
421
- ]
422
- },
423
- "metadata": {},
424
- "output_type": "display_data"
425
- },
426
- {
427
- "data": {
428
- "application/vnd.jupyter.widget-view+json": {
429
- "model_id": "578990cd94ef481ab41ae3ffe9dae522",
430
- "version_major": 2,
431
- "version_minor": 0
432
- },
433
- "text/plain": [
434
- "Map: 0%| | 0/1097 [00:00<?, ? examples/s]"
435
- ]
436
- },
437
- "metadata": {},
438
- "output_type": "display_data"
439
- },
440
- {
441
- "data": {
442
- "application/vnd.jupyter.widget-view+json": {
443
- "model_id": "6b038d4a6bb044cdbe4d96e436311426",
444
- "version_major": 2,
445
- "version_minor": 0
446
- },
447
- "text/plain": [
448
- "Creating parquet from Arrow format: 0%| | 0/11 [00:00<?, ?ba/s]"
449
- ]
450
- },
451
- "metadata": {},
452
- "output_type": "display_data"
453
- },
454
- {
455
- "data": {
456
- "application/vnd.jupyter.widget-view+json": {
457
- "model_id": "81475d2e23da48fe867e9931c92fe246",
458
- "version_major": 2,
459
- "version_minor": 0
460
- },
461
- "text/plain": [
462
- "README.md: 0%| | 0.00/2.90k [00:00<?, ?B/s]"
463
- ]
464
- },
465
- "metadata": {},
466
- "output_type": "display_data"
467
- },
468
- {
469
- "name": "stdout",
470
- "output_type": "stream",
471
- "text": [
472
- "[]\n"
473
- ]
474
- },
475
- {
476
- "data": {
477
- "application/vnd.jupyter.widget-view+json": {
478
- "model_id": "d805ff2d7b43482cb7d9ffe19a473bf1",
479
- "version_major": 2,
480
- "version_minor": 0
481
- },
482
- "text/plain": [
483
- "Uploading the dataset shards: 0%| | 0/1 [00:00<?, ?it/s]"
484
- ]
485
- },
486
- "metadata": {},
487
- "output_type": "display_data"
488
- },
489
- {
490
- "data": {
491
- "application/vnd.jupyter.widget-view+json": {
492
- "model_id": "f89273f09ed34a67bb905bfa80a82628",
493
- "version_major": 2,
494
- "version_minor": 0
495
- },
496
- "text/plain": [
497
- "Map: 0%| | 0/1097 [00:00<?, ? examples/s]"
498
- ]
499
- },
500
- "metadata": {},
501
- "output_type": "display_data"
502
- },
503
- {
504
- "data": {
505
- "application/vnd.jupyter.widget-view+json": {
506
- "model_id": "563022c1f761483fbb63a3e95d92e5ed",
507
- "version_major": 2,
508
- "version_minor": 0
509
- },
510
- "text/plain": [
511
- "Creating parquet from Arrow format: 0%| | 0/11 [00:00<?, ?ba/s]"
512
- ]
513
- },
514
- "metadata": {},
515
- "output_type": "display_data"
516
- },
517
- {
518
- "data": {
519
- "application/vnd.jupyter.widget-view+json": {
520
- "model_id": "466c0109b16d4a14a7587bf395e20270",
521
- "version_major": 2,
522
- "version_minor": 0
523
- },
524
- "text/plain": [
525
- "README.md: 0%| | 0.00/3.37k [00:00<?, ?B/s]"
526
- ]
527
- },
528
- "metadata": {},
529
- "output_type": "display_data"
530
- },
531
- {
532
- "name": "stdout",
533
- "output_type": "stream",
534
- "text": [
535
- "[]\n"
536
- ]
537
- },
538
- {
539
- "data": {
540
- "application/vnd.jupyter.widget-view+json": {
541
- "model_id": "6564df13321c4447bf713efb5dd7c0d4",
542
- "version_major": 2,
543
- "version_minor": 0
544
- },
545
- "text/plain": [
546
- "Uploading the dataset shards: 0%| | 0/1 [00:00<?, ?it/s]"
547
- ]
548
- },
549
- "metadata": {},
550
- "output_type": "display_data"
551
- },
552
- {
553
- "data": {
554
- "application/vnd.jupyter.widget-view+json": {
555
- "model_id": "328f67aa739a40a8a7c8d989e0614418",
556
- "version_major": 2,
557
- "version_minor": 0
558
- },
559
- "text/plain": [
560
- "Map: 0%| | 0/1097 [00:00<?, ? examples/s]"
561
- ]
562
- },
563
- "metadata": {},
564
- "output_type": "display_data"
565
- },
566
- {
567
- "data": {
568
- "application/vnd.jupyter.widget-view+json": {
569
- "model_id": "65e428172a2c40f7a8c6b267f3a1db54",
570
- "version_major": 2,
571
- "version_minor": 0
572
- },
573
- "text/plain": [
574
- "Creating parquet from Arrow format: 0%| | 0/11 [00:00<?, ?ba/s]"
575
- ]
576
- },
577
- "metadata": {},
578
- "output_type": "display_data"
579
- },
580
- {
581
- "data": {
582
- "application/vnd.jupyter.widget-view+json": {
583
- "model_id": "51699e5f26774ba3ad8c15434da11bb7",
584
- "version_major": 2,
585
- "version_minor": 0
586
- },
587
- "text/plain": [
588
- "README.md: 0%| | 0.00/3.47k [00:00<?, ?B/s]"
589
- ]
590
- },
591
- "metadata": {},
592
- "output_type": "display_data"
593
- },
594
- {
595
- "name": "stdout",
596
- "output_type": "stream",
597
- "text": [
598
- "[]\n"
599
- ]
600
- },
601
- {
602
- "data": {
603
- "application/vnd.jupyter.widget-view+json": {
604
- "model_id": "75d0a41d05334cba889bd566cd746f96",
605
- "version_major": 2,
606
- "version_minor": 0
607
- },
608
- "text/plain": [
609
- "Uploading the dataset shards: 0%| | 0/1 [00:00<?, ?it/s]"
610
- ]
611
- },
612
- "metadata": {},
613
- "output_type": "display_data"
614
- },
615
- {
616
- "data": {
617
- "application/vnd.jupyter.widget-view+json": {
618
- "model_id": "4223d1e159f6432d98a95a4868c31af5",
619
- "version_major": 2,
620
- "version_minor": 0
621
- },
622
- "text/plain": [
623
- "Map: 0%| | 0/1097 [00:00<?, ? examples/s]"
624
- ]
625
- },
626
- "metadata": {},
627
- "output_type": "display_data"
628
- },
629
- {
630
- "data": {
631
- "application/vnd.jupyter.widget-view+json": {
632
- "model_id": "32685d9c0ba54e8288b35d8c6b56369e",
633
- "version_major": 2,
634
- "version_minor": 0
635
- },
636
- "text/plain": [
637
- "Creating parquet from Arrow format: 0%| | 0/11 [00:00<?, ?ba/s]"
638
- ]
639
- },
640
- "metadata": {},
641
- "output_type": "display_data"
642
- },
643
- {
644
- "data": {
645
- "application/vnd.jupyter.widget-view+json": {
646
- "model_id": "fa33e335c997460b8047df3d2550fa8f",
647
- "version_major": 2,
648
- "version_minor": 0
649
- },
650
- "text/plain": [
651
- "README.md: 0%| | 0.00/3.95k [00:00<?, ?B/s]"
652
- ]
653
- },
654
- "metadata": {},
655
- "output_type": "display_data"
656
- },
657
- {
658
- "data": {
659
- "text/plain": [
660
- "CommitInfo(commit_url='https://huggingface.co/datasets/ivangtorre/second_americas_nlp_2022/commit/edd8ca4dc1e477443d98f7eace86ee02daf62347', commit_message='Upload dataset', commit_description='', oid='edd8ca4dc1e477443d98f7eace86ee02daf62347', pr_url=None, pr_revision=None, pr_num=None)"
661
- ]
662
- },
663
- "execution_count": 21,
664
- "metadata": {},
665
- "output_type": "execute_result"
666
- }
667
- ],
668
- "source": [
669
- "import pandas as pd\n",
670
- "from datasets import Dataset, Audio\n",
671
- "\n",
672
- "def flatten(xss):\n",
673
- " return [x for xs in xss for x in xs]\n",
674
- "\n",
675
- "def create_dataset(df):\n",
676
- " audio_dataset = Dataset.from_dict({\"audio\": flatten(df[\"file_name\"].values.tolist()),\n",
677
- " \"subset\": flatten(df[\"subset\"].values.tolist()),\n",
678
- " \"source_processed\": flatten(df[\"source_processed\"].values.tolist()),\n",
679
- " \"source_raw\": flatten(df[\"source_raw\"].values.tolist()),\n",
680
- " \"target_raw\": flatten(df[\"target_raw\"].values.tolist()),\n",
681
- " \"split\": flatten(df[\"split\"].values.tolist()),\n",
682
- " },\n",
683
- " ).cast_column(\"audio\", Audio())\n",
684
- " return(audio_dataset)\n",
685
- "\n",
686
- "\n",
687
- "def generate_df(language, split):\n",
688
- " # QUECHUA TRAIN\n",
689
- " with open(\"./../\"+language +\"_\"+split+\".tsv\") as f:\n",
690
- " lines = f.read().splitlines()\n",
691
- " lines2 = [l.split(\"\\t\") for l in lines if len(l.split(\"\\t\"))==4]\n",
692
- " asd = [l.split(\"\\t\")[0] for l in lines if len(l.split(\"\\t\"))>4]\n",
693
- " print(asd)\n",
694
- " df1 = pd.DataFrame(lines2[1::], columns =lines2[0:1])\n",
695
- " df1 = df1.assign(split=[split]*df1.shape[0])\n",
696
- " df1 = df1.assign(subset=[language]*df1.shape[0])\n",
697
- " df1 = df1.rename(columns={'wav': 'file_name'})\n",
698
- " df1['file_name'] = 'data/' + language + '/' + split +'/' + df1['file_name'].astype(str)\n",
699
- " audio_dataset = create_dataset(df)\n",
700
- " return audio_dataset\n",
701
- "\n",
702
- "\n",
703
- "\n",
704
- "audio_dataset = generate_df(\"quechua\", \"train\")\n",
705
- "audio_dataset.push_to_hub(\"ivangtorre/second_americas_nlp_2022\", \"quechua\", split=\"train\")\n",
706
- "audio_dataset = generate_df(\"quechua\", \"dev\")\n",
707
- "audio_dataset.push_to_hub(\"ivangtorre/second_americas_nlp_2022\", \"quechua\", split=\"dev\")\n",
708
- "\n",
709
- "audio_dataset = generate_df(\"guarani\", \"train\")\n",
710
- "audio_dataset.push_to_hub(\"ivangtorre/second_americas_nlp_2022\", \"guarani\", split=\"train\")\n",
711
- "audio_dataset = generate_df(\"guarani\", \"dev\")\n",
712
- "audio_dataset.push_to_hub(\"ivangtorre/second_americas_nlp_2022\", \"guarani\", split=\"dev\")\n",
713
- "\n",
714
- "audio_dataset = generate_df(\"kotiria\", \"dev\")\n",
715
- "audio_dataset.push_to_hub(\"ivangtorre/second_americas_nlp_2022\", \"kotiria\", split=\"train\")\n",
716
- "audio_dataset = generate_df(\"kotiria\", \"dev\")\n",
717
- "audio_dataset.push_to_hub(\"ivangtorre/second_americas_nlp_2022\", \"kotiria\", split=\"dev\")\n",
718
- "\n",
719
- "audio_dataset = generate_df(\"bribri\", \"train\")\n",
720
- "audio_dataset.push_to_hub(\"ivangtorre/second_americas_nlp_2022\", \"bribri\", split=\"train\")\n",
721
- "audio_dataset = generate_df(\"bribri\", \"dev\")\n",
722
- "audio_dataset.push_to_hub(\"ivangtorre/second_americas_nlp_2022\", \"bribri\", split=\"dev\")\n",
723
- "\n",
724
- "audio_dataset = generate_df(\"waikhana\", \"dev\")\n",
725
- "audio_dataset.push_to_hub(\"ivangtorre/second_americas_nlp_2022\", \"waikhana\", split=\"train\")\n",
726
- "audio_dataset = generate_df(\"waikhana\", \"dev\")\n",
727
- "audio_dataset.push_to_hub(\"ivangtorre/second_americas_nlp_2022\", \"waikhana\", split=\"dev\")\n"
728
- ]
729
- },
730
- {
731
- "cell_type": "code",
732
- "execution_count": 2,
733
- "id": "a1f02703",
734
- "metadata": {
735
- "scrolled": true
736
- },
737
- "outputs": [],
738
- "source": [
739
- "#from datasets import load_dataset\n",
740
- "#dataset = load_dataset(\"audiofolder\", data_dir=\"second_americas_nlp_2022\")\n"
741
- ]
742
- },
743
- {
744
- "cell_type": "markdown",
745
- "id": "5eaa7c93",
746
- "metadata": {},
747
- "source": [
748
- "# EVALUATE MODELS\n"
749
- ]
750
- },
751
- {
752
- "cell_type": "markdown",
753
- "id": "2e4e15c9",
754
- "metadata": {},
755
- "source": [
756
- "## QUECHUA"
757
- ]
758
- },
759
- {
760
- "cell_type": "code",
761
- "execution_count": 8,
762
- "id": "e165f4bf",
763
- "metadata": {
764
- "scrolled": true
765
- },
766
- "outputs": [
767
- {
768
- "data": {
769
- "application/vnd.jupyter.widget-view+json": {
770
- "model_id": "9c96f2ce38474bc990e57387acd56fc8",
771
- "version_major": 2,
772
- "version_minor": 0
773
- },
774
- "text/plain": [
775
- "Map: 0%| | 0/250 [00:00<?, ? examples/s]"
776
- ]
777
- },
778
- "metadata": {},
779
- "output_type": "display_data"
780
- },
781
- {
782
- "ename": "LibsndfileError",
783
- "evalue": "Error opening 'data/quechua/dev/quechua000573.wav': System error.",
784
- "output_type": "error",
785
- "traceback": [
786
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
787
- "\u001b[0;31mLibsndfileError\u001b[0m Traceback (most recent call last)",
788
- "Input \u001b[0;32mIn [8]\u001b[0m, in \u001b[0;36m<cell line: 25>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 22\u001b[0m batch[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtranscription\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m processor\u001b[38;5;241m.\u001b[39mbatch_decode(predicted_ids)\n\u001b[1;32m 23\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m batch\n\u001b[0;32m---> 25\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mquechua\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmap\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmap_to_pred\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mbatched\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mbatch_size\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 27\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCER:\u001b[39m\u001b[38;5;124m\"\u001b[39m, cer(result[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msource_processed\u001b[39m\u001b[38;5;124m\"\u001b[39m], result[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtranscription\u001b[39m\u001b[38;5;124m\"\u001b[39m]))\n",
789
- "File \u001b[0;32m~/.local/lib/python3.10/site-packages/datasets/arrow_dataset.py:602\u001b[0m, in \u001b[0;36mtransmit_tasks.<locals>.wrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 600\u001b[0m \u001b[38;5;28mself\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDataset\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m=\u001b[39m kwargs\u001b[38;5;241m.\u001b[39mpop(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mself\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 601\u001b[0m \u001b[38;5;66;03m# apply actual function\u001b[39;00m\n\u001b[0;32m--> 602\u001b[0m out: Union[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDataset\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDatasetDict\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 603\u001b[0m datasets: List[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDataset\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(out\u001b[38;5;241m.\u001b[39mvalues()) \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(out, \u001b[38;5;28mdict\u001b[39m) \u001b[38;5;28;01melse\u001b[39;00m [out]\n\u001b[1;32m 604\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m dataset \u001b[38;5;129;01min\u001b[39;00m datasets:\n\u001b[1;32m 605\u001b[0m \u001b[38;5;66;03m# Remove task templates if a column mapping of the template is no longer valid\u001b[39;00m\n",
790
- "File \u001b[0;32m~/.local/lib/python3.10/site-packages/datasets/arrow_dataset.py:567\u001b[0m, in \u001b[0;36mtransmit_format.<locals>.wrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 560\u001b[0m self_format \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 561\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtype\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_format_type,\n\u001b[1;32m 562\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mformat_kwargs\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_format_kwargs,\n\u001b[1;32m 563\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcolumns\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_format_columns,\n\u001b[1;32m 564\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124moutput_all_columns\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_output_all_columns,\n\u001b[1;32m 565\u001b[0m }\n\u001b[1;32m 566\u001b[0m \u001b[38;5;66;03m# apply actual function\u001b[39;00m\n\u001b[0;32m--> 567\u001b[0m out: Union[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDataset\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDatasetDict\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 568\u001b[0m datasets: List[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDataset\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(out\u001b[38;5;241m.\u001b[39mvalues()) \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(out, \u001b[38;5;28mdict\u001b[39m) \u001b[38;5;28;01melse\u001b[39;00m [out]\n\u001b[1;32m 569\u001b[0m \u001b[38;5;66;03m# re-apply format to the output\u001b[39;00m\n",
791
- "File \u001b[0;32m~/.local/lib/python3.10/site-packages/datasets/arrow_dataset.py:3156\u001b[0m, in \u001b[0;36mDataset.map\u001b[0;34m(self, function, with_indices, with_rank, input_columns, batched, batch_size, drop_last_batch, remove_columns, keep_in_memory, load_from_cache_file, cache_file_name, writer_batch_size, features, disable_nullable, fn_kwargs, num_proc, suffix_template, new_fingerprint, desc)\u001b[0m\n\u001b[1;32m 3150\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m transformed_dataset \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 3151\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m hf_tqdm(\n\u001b[1;32m 3152\u001b[0m unit\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m examples\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 3153\u001b[0m total\u001b[38;5;241m=\u001b[39mpbar_total,\n\u001b[1;32m 3154\u001b[0m desc\u001b[38;5;241m=\u001b[39mdesc \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMap\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 3155\u001b[0m ) \u001b[38;5;28;01mas\u001b[39;00m pbar:\n\u001b[0;32m-> 3156\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m rank, done, content \u001b[38;5;129;01min\u001b[39;00m Dataset\u001b[38;5;241m.\u001b[39m_map_single(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mdataset_kwargs):\n\u001b[1;32m 3157\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m done:\n\u001b[1;32m 3158\u001b[0m shards_done \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n",
792
- "File \u001b[0;32m~/.local/lib/python3.10/site-packages/datasets/arrow_dataset.py:3547\u001b[0m, in \u001b[0;36mDataset._map_single\u001b[0;34m(shard, function, with_indices, with_rank, input_columns, batched, batch_size, drop_last_batch, remove_columns, keep_in_memory, cache_file_name, writer_batch_size, features, disable_nullable, fn_kwargs, new_fingerprint, rank, offset)\u001b[0m\n\u001b[1;32m 3543\u001b[0m indices \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(\n\u001b[1;32m 3544\u001b[0m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m*\u001b[39m(\u001b[38;5;28mslice\u001b[39m(i, i \u001b[38;5;241m+\u001b[39m batch_size)\u001b[38;5;241m.\u001b[39mindices(shard\u001b[38;5;241m.\u001b[39mnum_rows)))\n\u001b[1;32m 3545\u001b[0m ) \u001b[38;5;66;03m# Something simpler?\u001b[39;00m\n\u001b[1;32m 3546\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m-> 3547\u001b[0m batch \u001b[38;5;241m=\u001b[39m \u001b[43mapply_function_on_filtered_inputs\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 3548\u001b[0m \u001b[43m \u001b[49m\u001b[43mbatch\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 3549\u001b[0m \u001b[43m \u001b[49m\u001b[43mindices\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 3550\u001b[0m \u001b[43m \u001b[49m\u001b[43mcheck_same_num_examples\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mlen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mshard\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlist_indexes\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m>\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 3551\u001b[0m \u001b[43m \u001b[49m\u001b[43moffset\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43moffset\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 3552\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3553\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m NumExamplesMismatchError:\n\u001b[1;32m 3554\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m DatasetTransformationNotAllowedError(\n\u001b[1;32m 3555\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mUsing `.map` in batched mode on a dataset with attached indexes is allowed only if it doesn\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt create or remove existing examples. You can first run `.drop_index() to remove your index and then re-add it.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 3556\u001b[0m ) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n",
793
- "File \u001b[0;32m~/.local/lib/python3.10/site-packages/datasets/arrow_dataset.py:3416\u001b[0m, in \u001b[0;36mDataset._map_single.<locals>.apply_function_on_filtered_inputs\u001b[0;34m(pa_inputs, indices, check_same_num_examples, offset)\u001b[0m\n\u001b[1;32m 3414\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m with_rank:\n\u001b[1;32m 3415\u001b[0m additional_args \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m (rank,)\n\u001b[0;32m-> 3416\u001b[0m processed_inputs \u001b[38;5;241m=\u001b[39m \u001b[43mfunction\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mfn_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43madditional_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mfn_kwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3417\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(processed_inputs, LazyDict):\n\u001b[1;32m 3418\u001b[0m processed_inputs \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 3419\u001b[0m k: v \u001b[38;5;28;01mfor\u001b[39;00m k, v \u001b[38;5;129;01min\u001b[39;00m processed_inputs\u001b[38;5;241m.\u001b[39mdata\u001b[38;5;241m.\u001b[39mitems() \u001b[38;5;28;01mif\u001b[39;00m k \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m processed_inputs\u001b[38;5;241m.\u001b[39mkeys_to_format\n\u001b[1;32m 3420\u001b[0m }\n",
794
- "Input \u001b[0;32mIn [8]\u001b[0m, in \u001b[0;36mmap_to_pred\u001b[0;34m(batch)\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mmap_to_pred\u001b[39m(batch):\n\u001b[0;32m---> 16\u001b[0m wav, curr_sample_rate \u001b[38;5;241m=\u001b[39m \u001b[43msf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mread\u001b[49m\u001b[43m(\u001b[49m\u001b[43mbatch\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mfile_name\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdtype\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mfloat32\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 17\u001b[0m feats \u001b[38;5;241m=\u001b[39m torch\u001b[38;5;241m.\u001b[39mfrom_numpy(wav)\u001b[38;5;241m.\u001b[39mfloat()\n\u001b[1;32m 18\u001b[0m feats \u001b[38;5;241m=\u001b[39m F\u001b[38;5;241m.\u001b[39mlayer_norm(feats, feats\u001b[38;5;241m.\u001b[39mshape) \u001b[38;5;66;03m# Normalization performed during finetuning\u001b[39;00m\n",
795
- "File \u001b[0;32m~/.local/lib/python3.10/site-packages/soundfile.py:285\u001b[0m, in \u001b[0;36mread\u001b[0;34m(file, frames, start, stop, dtype, always_2d, fill_value, out, samplerate, channels, format, subtype, endian, closefd)\u001b[0m\n\u001b[1;32m 199\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mread\u001b[39m(file, frames\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m, start\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0\u001b[39m, stop\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, dtype\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfloat64\u001b[39m\u001b[38;5;124m'\u001b[39m, always_2d\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[1;32m 200\u001b[0m fill_value\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, out\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, samplerate\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, channels\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 201\u001b[0m \u001b[38;5;28mformat\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, subtype\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, endian\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, closefd\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m):\n\u001b[1;32m 202\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Provide audio data from a sound file as NumPy array.\u001b[39;00m\n\u001b[1;32m 203\u001b[0m \n\u001b[1;32m 204\u001b[0m \u001b[38;5;124;03m By default, the whole file is read from the beginning, but the\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 283\u001b[0m \n\u001b[1;32m 284\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 285\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[43mSoundFile\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mr\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msamplerate\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mchannels\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 286\u001b[0m \u001b[43m \u001b[49m\u001b[43msubtype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mendian\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mclosefd\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m f:\n\u001b[1;32m 287\u001b[0m frames \u001b[38;5;241m=\u001b[39m f\u001b[38;5;241m.\u001b[39m_prepare_read(start, stop, frames)\n\u001b[1;32m 288\u001b[0m data \u001b[38;5;241m=\u001b[39m f\u001b[38;5;241m.\u001b[39mread(frames, dtype, always_2d, fill_value, out)\n",
796
- "File \u001b[0;32m~/.local/lib/python3.10/site-packages/soundfile.py:658\u001b[0m, in \u001b[0;36mSoundFile.__init__\u001b[0;34m(self, file, mode, samplerate, channels, subtype, endian, format, closefd)\u001b[0m\n\u001b[1;32m 655\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_mode \u001b[38;5;241m=\u001b[39m mode\n\u001b[1;32m 656\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_info \u001b[38;5;241m=\u001b[39m _create_info_struct(file, mode, samplerate, channels,\n\u001b[1;32m 657\u001b[0m \u001b[38;5;28mformat\u001b[39m, subtype, endian)\n\u001b[0;32m--> 658\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_file \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_open\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmode_int\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mclosefd\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 659\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mset\u001b[39m(mode)\u001b[38;5;241m.\u001b[39missuperset(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mr+\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mseekable():\n\u001b[1;32m 660\u001b[0m \u001b[38;5;66;03m# Move write position to 0 (like in Python file objects)\u001b[39;00m\n\u001b[1;32m 661\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mseek(\u001b[38;5;241m0\u001b[39m)\n",
797
- "File \u001b[0;32m~/.local/lib/python3.10/site-packages/soundfile.py:1216\u001b[0m, in \u001b[0;36mSoundFile._open\u001b[0;34m(self, file, mode_int, closefd)\u001b[0m\n\u001b[1;32m 1213\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m file_ptr \u001b[38;5;241m==\u001b[39m _ffi\u001b[38;5;241m.\u001b[39mNULL:\n\u001b[1;32m 1214\u001b[0m \u001b[38;5;66;03m# get the actual error code\u001b[39;00m\n\u001b[1;32m 1215\u001b[0m err \u001b[38;5;241m=\u001b[39m _snd\u001b[38;5;241m.\u001b[39msf_error(file_ptr)\n\u001b[0;32m-> 1216\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m LibsndfileError(err, prefix\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mError opening \u001b[39m\u001b[38;5;132;01m{0!r}\u001b[39;00m\u001b[38;5;124m: \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mformat(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mname))\n\u001b[1;32m 1217\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m mode_int \u001b[38;5;241m==\u001b[39m _snd\u001b[38;5;241m.\u001b[39mSFM_WRITE:\n\u001b[1;32m 1218\u001b[0m \u001b[38;5;66;03m# Due to a bug in libsndfile version <= 1.0.25, frames != 0\u001b[39;00m\n\u001b[1;32m 1219\u001b[0m \u001b[38;5;66;03m# when opening a named pipe in SFM_WRITE mode.\u001b[39;00m\n\u001b[1;32m 1220\u001b[0m \u001b[38;5;66;03m# See http://github.com/erikd/libsndfile/issues/77.\u001b[39;00m\n\u001b[1;32m 1221\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_info\u001b[38;5;241m.\u001b[39mframes \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m\n",
798
- "\u001b[0;31mLibsndfileError\u001b[0m: Error opening 'data/quechua/dev/quechua000573.wav': System error."
799
- ]
800
- }
801
- ],
802
- "source": [
803
- "from datasets import load_dataset\n",
804
- "from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor\n",
805
- "import torch\n",
806
- "from jiwer import cer\n",
807
- "import torch.nn.functional as F\n",
808
- "from datasets import load_dataset\n",
809
- "import soundfile as sf\n",
810
- "\n",
811
- "americasnlp = load_dataset(\"ivangtorre/second_americas_nlp_2022\", split=\"dev\")\n",
812
- "quechua = americasnlp.filter(lambda language: language['subset']=='quechua')\n",
813
- "\n",
814
- "model = Wav2Vec2ForCTC.from_pretrained(\"ivangtorre/wav2vec2-xlsr-300m-quechua\")\n",
815
- "processor = Wav2Vec2Processor.from_pretrained(\"ivangtorre/wav2vec2-xlsr-300m-quechua\")\n",
816
- "\n",
817
- "def map_to_pred(batch):\n",
818
- " wav, curr_sample_rate = sf.read(batch[\"file_name\"][0], dtype=\"float32\")\n",
819
- " feats = torch.from_numpy(wav).float()\n",
820
- " feats = F.layer_norm(feats, feats.shape) # Normalization performed during finetuning\n",
821
- " feats = torch.unsqueeze(feats, 0)\n",
822
- " logits = model(feats).logits\n",
823
- " predicted_ids = torch.argmax(logits, dim=-1)\n",
824
- " batch[\"transcription\"] = processor.batch_decode(predicted_ids)\n",
825
- " return batch\n",
826
- "\n",
827
- "result = quechua.map(map_to_pred, batched=True, batch_size=1)\n",
828
- "\n",
829
- "print(\"CER:\", cer(result[\"source_processed\"], result[\"transcription\"]))\n"
830
- ]
831
- },
832
- {
833
- "cell_type": "markdown",
834
- "id": "8e29bc13",
835
- "metadata": {},
836
- "source": [
837
- "## BRIBRI\n"
838
- ]
839
- },
840
- {
841
- "cell_type": "code",
842
- "execution_count": 7,
843
- "id": "7cdec414",
844
- "metadata": {},
845
- "outputs": [
846
- {
847
- "data": {
848
- "text/plain": [
849
- "'data/quechua/dev/quechua000573.wav'"
850
- ]
851
- },
852
- "execution_count": 7,
853
- "metadata": {},
854
- "output_type": "execute_result"
855
- }
856
- ],
857
- "source": [
858
- "quechua[0:1][\"file_name\"][0]"
859
- ]
860
- }
861
- ],
862
- "metadata": {
863
- "kernelspec": {
864
- "display_name": "Python 3 (ipykernel)",
865
- "language": "python",
866
- "name": "python3"
867
- },
868
- "language_info": {
869
- "codemirror_mode": {
870
- "name": "ipython",
871
- "version": 3
872
- },
873
- "file_extension": ".py",
874
- "mimetype": "text/x-python",
875
- "name": "python",
876
- "nbconvert_exporter": "python",
877
- "pygments_lexer": "ipython3",
878
- "version": "3.10.12"
879
- }
880
- },
881
- "nbformat": 4,
882
- "nbformat_minor": 5
883
- }