Masum Billah commited on
Commit
a6cb919
·
1 Parent(s): d09ceca
Files changed (1) hide show
  1. train_whisper_arabic_letters.ipynb +521 -684
train_whisper_arabic_letters.ipynb CHANGED
@@ -1,686 +1,523 @@
1
  {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {
6
-
7
- },
8
- "source": [
9
- "# Fine-tune Whisper (small) on Arabic Letter Pronunciation\n",
10
- "\n",
11
- "Fine-tunes `openai/whisper-small` to transcribe isolated Arabic letter audio clips (28 letters, ~22k one-second\n",
12
- "clips, `whisper_dataset/{train,validation,test}` in HuggingFace `audiofolder` format).\n",
13
- "\n",
14
- "**Pipeline:** install deps -\u003e mount Drive -\u003e unzip dataset -\u003e load `datasets` -\u003e preprocess audio/text -\u003e\n",
15
- "fine-tune with `Seq2SeqTrainer` (checkpointing to Drive, early stopping, mixed precision) -\u003e evaluate\n",
16
- "(WER + per-letter exact-match accuracy) -\u003e save/export final model -\u003e run inference.\n",
17
- "\n",
18
- "**Before running:** upload `whisper_dataset.zip` to your Google Drive and set `DRIVE_ZIP_PATH` in the\n",
19
- "\"Configuration\" cell below. Runtime -\u003e Change runtime type -\u003e GPU (T4 is sufficient)."
20
- ]
21
- },
22
- {
23
- "cell_type": "code",
24
- "execution_count": null,
25
- "metadata": {
26
-
27
- },
28
- "outputs": [
29
-
30
- ],
31
- "source": [
32
- "!nvidia-smi"
33
- ]
34
- },
35
- {
36
- "cell_type": "markdown",
37
- "metadata": {
38
-
39
- },
40
- "source": [
41
- "## 1. Install dependencies"
42
- ]
43
- },
44
- {
45
- "cell_type": "code",
46
- "execution_count": null,
47
- "metadata": {
48
-
49
- },
50
- "outputs": [
51
-
52
- ],
53
- "source": [
54
- "!pip install -q \"transformers==4.44.2\" \"datasets==2.21.0\" \"accelerate==0.34.2\" \\\n",
55
- " \"evaluate==0.4.3\" \"jiwer==3.0.4\" \"soundfile==0.12.1\" \"librosa==0.10.2.post1\" \\\n",
56
- " \"tensorboard==2.17.1\""
57
- ]
58
- },
59
- {
60
- "cell_type": "code",
61
- "execution_count": null,
62
- "metadata": {
63
-
64
- },
65
- "outputs": [
66
-
67
- ],
68
- "source": [
69
- "import os\n",
70
- "import random\n",
71
- "import shutil\n",
72
- "from dataclasses import dataclass\n",
73
- "from pathlib import Path\n",
74
- "from typing import Any, Dict, List, Union\n",
75
- "\n",
76
- "import numpy as np\n",
77
- "import torch\n",
78
- "from datasets import Audio, load_dataset\n",
79
- "from transformers import (\n",
80
- " EarlyStoppingCallback,\n",
81
- " Seq2SeqTrainer,\n",
82
- " Seq2SeqTrainingArguments,\n",
83
- " WhisperForConditionalGeneration,\n",
84
- " WhisperProcessor,\n",
85
- ")\n",
86
- "\n",
87
- "SEED = 42\n",
88
- "random.seed(SEED)\n",
89
- "np.random.seed(SEED)\n",
90
- "torch.manual_seed(SEED)\n",
91
- "\n",
92
- "DEVICE = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
93
- "print(f\"Using device: {DEVICE}\")"
94
- ]
95
- },
96
- {
97
- "cell_type": "markdown",
98
- "metadata": {
99
-
100
- },
101
- "source": [
102
- "## 2. Configuration \u0026 mount Google Drive\n",
103
- "\n",
104
- "Set `DRIVE_ZIP_PATH` to wherever you uploaded `whisper_dataset.zip` in your Drive. Checkpoints and the\n",
105
- "final model are written under `DRIVE_OUTPUT_DIR` so training survives Colab disconnects -- rerunning the\n",
106
- "notebook will auto-resume from the latest checkpoint."
107
- ]
108
- },
109
- {
110
- "cell_type": "code",
111
- "execution_count": null,
112
- "metadata": {
113
-
114
- },
115
- "outputs": [
116
-
117
- ],
118
- "source": [
119
- "from google.colab import drive\n",
120
- "\n",
121
- "drive.mount(\"/content/drive\")\n",
122
- "\n",
123
- "# --- Edit these two paths for your Drive layout ---\n",
124
- "DRIVE_ZIP_PATH = \"/content/drive/MyDrive/datasets/whisper_dataset.zip\"\n",
125
- "DRIVE_OUTPUT_DIR = \"/content/drive/MyDrive/arabic_whisper_letters\"\n",
126
- "# ----------------------------------------------------\n",
127
- "\n",
128
- "LOCAL_DATA_DIR = \"/content/whisper_dataset\"\n",
129
- "MODEL_CHECKPOINT = \"openai/whisper-small\"\n",
130
- "LANGUAGE = \"arabic\"\n",
131
- "TASK = \"transcribe\"\n",
132
- "\n",
133
- "os.makedirs(DRIVE_OUTPUT_DIR, exist_ok=True)\n",
134
- "assert os.path.exists(DRIVE_ZIP_PATH), (\n",
135
- " f\"{DRIVE_ZIP_PATH} not found -- upload whisper_dataset.zip to your Drive and update DRIVE_ZIP_PATH.\"\n",
136
- ")\n",
137
- "print(\"Drive mounted. Zip found at:\", DRIVE_ZIP_PATH)"
138
- ]
139
- },
140
- {
141
- "cell_type": "markdown",
142
- "metadata": {
143
-
144
- },
145
- "source": [
146
- "## 3. Unzip the dataset to local (fast) disk\n",
147
- "\n",
148
- "Extracting to `/content` instead of reading straight from Drive avoids the slow, flaky I/O of training\n",
149
- "against a mounted Drive folder."
150
- ]
151
- },
152
- {
153
- "cell_type": "code",
154
- "execution_count": null,
155
- "metadata": {
156
-
157
- },
158
- "outputs": [
159
-
160
- ],
161
- "source": [
162
- "if not os.path.isdir(LOCAL_DATA_DIR):\n",
163
- " print(\"Extracting dataset (one-time)...\")\n",
164
- " shutil.unpack_archive(DRIVE_ZIP_PATH, \"/content\")\n",
165
- " print(\"Done.\")\n",
166
- "else:\n",
167
- " print(\"Dataset already extracted at\", LOCAL_DATA_DIR)\n",
168
- "\n",
169
- "for split in (\"train\", \"validation\", \"test\"):\n",
170
- " n = sum(1 for _ in open(f\"{LOCAL_DATA_DIR}/{split}/metadata.csv\", encoding=\"utf-8\")) - 1\n",
171
- " print(f\"{split}: {n} rows\")"
172
- ]
173
- },
174
- {
175
- "cell_type": "markdown",
176
- "metadata": {
177
-
178
- },
179
- "source": [
180
- "## 4. Load the dataset"
181
- ]
182
- },
183
- {
184
- "cell_type": "code",
185
- "execution_count": null,
186
- "metadata": {
187
-
188
- },
189
- "outputs": [
190
-
191
- ],
192
- "source": [
193
- "raw_datasets = load_dataset(\"audiofolder\", data_dir=LOCAL_DATA_DIR)\n",
194
- "print(raw_datasets)\n",
195
- "\n",
196
- "# sanity check: every split should cover all 28 letters\n",
197
- "for split in raw_datasets:\n",
198
- " labels = set(raw_datasets[split][\"label\"])\n",
199
- " print(f\"{split}: {len(labels)} unique letters, {len(raw_datasets[split])} examples\")\n",
200
- "\n",
201
- "print(\"\\nSample example:\")\n",
202
- "example = raw_datasets[\"train\"][0]\n",
203
- "print({k: v for k, v in example.items() if k != \"audio\"})"
204
- ]
205
- },
206
- {
207
- "cell_type": "markdown",
208
- "metadata": {
209
-
210
- },
211
- "source": [
212
- "## 5. Load the Whisper processor (feature extractor + tokenizer)"
213
- ]
214
- },
215
- {
216
- "cell_type": "code",
217
- "execution_count": null,
218
- "metadata": {
219
-
220
- },
221
- "outputs": [
222
-
223
- ],
224
- "source": [
225
- "processor = WhisperProcessor.from_pretrained(MODEL_CHECKPOINT, language=LANGUAGE, task=TASK)\n",
226
- "feature_extractor = processor.feature_extractor\n",
227
- "tokenizer = processor.tokenizer"
228
- ]
229
- },
230
- {
231
- "cell_type": "markdown",
232
- "metadata": {
233
-
234
- },
235
- "source": [
236
- "## 6. Preprocess: resample audio to 16kHz, extract log-mel features, tokenize labels"
237
- ]
238
- },
239
- {
240
- "cell_type": "code",
241
- "execution_count": null,
242
- "metadata": {
243
-
244
- },
245
- "outputs": [
246
-
247
- ],
248
- "source": [
249
- "raw_datasets = raw_datasets.cast_column(\"audio\", Audio(sampling_rate=16000))\n",
250
- "\n",
251
- "\n",
252
- "def prepare_batch(batch):\n",
253
- " audio = batch[\"audio\"]\n",
254
- " batch[\"input_features\"] = feature_extractor(\n",
255
- " audio[\"array\"], sampling_rate=audio[\"sampling_rate\"]\n",
256
- " ).input_features[0]\n",
257
- " batch[\"labels\"] = tokenizer(batch[\"transcription\"]).input_ids\n",
258
- " return batch\n",
259
- "\n",
260
- "\n",
261
- "vectorized_datasets = raw_datasets.map(\n",
262
- " prepare_batch,\n",
263
- " remove_columns=raw_datasets[\"train\"].column_names,\n",
264
- " num_proc=2,\n",
265
- " desc=\"Extracting features\",\n",
266
- ")"
267
- ]
268
- },
269
- {
270
- "cell_type": "markdown",
271
- "metadata": {
272
-
273
- },
274
- "source": [
275
- "## 7. Data collator (pads audio features and label sequences separately)"
276
- ]
277
- },
278
- {
279
- "cell_type": "code",
280
- "execution_count": null,
281
- "metadata": {
282
-
283
- },
284
- "outputs": [
285
-
286
- ],
287
- "source": [
288
- "@dataclass\n",
289
- "class DataCollatorSpeechSeq2SeqWithPadding:\n",
290
- " processor: Any\n",
291
- "\n",
292
- " def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) -\u003e Dict[str, torch.Tensor]:\n",
293
- " input_features = [{\"input_features\": f[\"input_features\"]} for f in features]\n",
294
- " batch = self.processor.feature_extractor.pad(input_features, return_tensors=\"pt\")\n",
295
- "\n",
296
- " label_features = [{\"input_ids\": f[\"labels\"]} for f in features]\n",
297
- " labels_batch = self.processor.tokenizer.pad(label_features, return_tensors=\"pt\")\n",
298
- " labels = labels_batch[\"input_ids\"].masked_fill(labels_batch.attention_mask.ne(1), -100)\n",
299
- "\n",
300
- " if (labels[:, 0] == self.processor.tokenizer.bos_token_id).all().cpu().item():\n",
301
- " labels = labels[:, 1:]\n",
302
- "\n",
303
- " batch[\"labels\"] = labels\n",
304
- " return batch\n",
305
- "\n",
306
- "\n",
307
- "data_collator = DataCollatorSpeechSeq2SeqWithPadding(processor=processor)"
308
- ]
309
- },
310
- {
311
- "cell_type": "markdown",
312
- "metadata": {
313
-
314
- },
315
- "source": [
316
- "## 8. Load the model"
317
- ]
318
- },
319
- {
320
- "cell_type": "code",
321
- "execution_count": null,
322
- "metadata": {
323
-
324
- },
325
- "outputs": [
326
-
327
- ],
328
- "source": [
329
- "model = WhisperForConditionalGeneration.from_pretrained(MODEL_CHECKPOINT)\n",
330
- "model.generation_config.language = LANGUAGE\n",
331
- "model.generation_config.task = TASK\n",
332
- "model.generation_config.forced_decoder_ids = None\n",
333
- "model.config.suppress_tokens = []\n",
334
- "model.config.use_cache = False # required with gradient checkpointing"
335
- ]
336
- },
337
- {
338
- "cell_type": "markdown",
339
- "metadata": {
340
-
341
- },
342
- "source": [
343
- "## 9. Metrics: word error rate + per-letter exact-match accuracy\n",
344
- "\n",
345
- "WER is the standard ASR metric; exact-match accuracy is more interpretable here since every label is a\n",
346
- "single letter, so it doubles as classification accuracy over the 28 letters."
347
- ]
348
- },
349
- {
350
- "cell_type": "code",
351
- "execution_count": null,
352
- "metadata": {
353
-
354
- },
355
- "outputs": [
356
-
357
- ],
358
- "source": [
359
- "import evaluate\n",
360
- "\n",
361
- "wer_metric = evaluate.load(\"wer\")\n",
362
- "\n",
363
- "\n",
364
- "def compute_metrics(pred):\n",
365
- " pred_ids = pred.predictions\n",
366
- " label_ids = pred.label_ids\n",
367
- " label_ids[label_ids == -100] = tokenizer.pad_token_id\n",
368
- "\n",
369
- " pred_str = tokenizer.batch_decode(pred_ids, skip_special_tokens=True)\n",
370
- " label_str = tokenizer.batch_decode(label_ids, skip_special_tokens=True)\n",
371
- "\n",
372
- " wer = 100 * wer_metric.compute(predictions=pred_str, references=label_str)\n",
373
- " accuracy = 100 * np.mean(\n",
374
- " [p.strip() == l.strip() for p, l in zip(pred_str, label_str)]\n",
375
- " )\n",
376
- " return {\"wer\": wer, \"accuracy\": accuracy}"
377
- ]
378
- },
379
- {
380
- "cell_type": "markdown",
381
- "metadata": {
382
-
383
- },
384
- "source": [
385
- "## 10. Training arguments\n",
386
- "\n",
387
- "Checkpoints go to `DRIVE_OUTPUT_DIR` so a disconnect does not lose progress. `load_best_model_at_end` +\n",
388
- "`EarlyStoppingCallback` (next cell) stop training once WER stops improving instead of burning a fixed\n",
389
- "budget of steps."
390
- ]
391
- },
392
- {
393
- "cell_type": "code",
394
- "execution_count": null,
395
- "metadata": {
396
-
397
- },
398
- "outputs": [
399
-
400
- ],
401
- "source": [
402
- "training_args = Seq2SeqTrainingArguments(\n",
403
- " output_dir=DRIVE_OUTPUT_DIR,\n",
404
- " per_device_train_batch_size=16,\n",
405
- " gradient_accumulation_steps=2,\n",
406
- " per_device_eval_batch_size=16,\n",
407
- " learning_rate=1e-5,\n",
408
- " warmup_steps=500,\n",
409
- " num_train_epochs=10,\n",
410
- " gradient_checkpointing=True,\n",
411
- " fp16=(DEVICE == \"cuda\"),\n",
412
- " eval_strategy=\"steps\",\n",
413
- " eval_steps=500,\n",
414
- " save_strategy=\"steps\",\n",
415
- " save_steps=500,\n",
416
- " save_total_limit=3,\n",
417
- " logging_steps=50,\n",
418
- " logging_dir=f\"{DRIVE_OUTPUT_DIR}/logs\",\n",
419
- " report_to=[\"tensorboard\"],\n",
420
- " predict_with_generate=True,\n",
421
- " generation_max_length=8,\n",
422
- " load_best_model_at_end=True,\n",
423
- " metric_for_best_model=\"wer\",\n",
424
- " greater_is_better=False,\n",
425
- " dataloader_num_workers=2,\n",
426
- " seed=SEED,\n",
427
- ")"
428
- ]
429
- },
430
- {
431
- "cell_type": "code",
432
- "execution_count": null,
433
- "metadata": {
434
-
435
- },
436
- "outputs": [
437
-
438
- ],
439
- "source": [
440
- "trainer = Seq2SeqTrainer(\n",
441
- " args=training_args,\n",
442
- " model=model,\n",
443
- " train_dataset=vectorized_datasets[\"train\"],\n",
444
- " eval_dataset=vectorized_datasets[\"validation\"],\n",
445
- " data_collator=data_collator,\n",
446
- " compute_metrics=compute_metrics,\n",
447
- " tokenizer=processor.feature_extractor,\n",
448
- " callbacks=[EarlyStoppingCallback(early_stopping_patience=5)],\n",
449
- ")"
450
- ]
451
- },
452
- {
453
- "cell_type": "markdown",
454
- "metadata": {
455
-
456
- },
457
- "source": [
458
- "## 11. Train\n",
459
- "\n",
460
- "Auto-resumes from the latest checkpoint in `DRIVE_OUTPUT_DIR` if one exists (e.g. after a Colab\n",
461
- "disconnect) -- rerun this cell to continue rather than restarting from scratch."
462
- ]
463
- },
464
- {
465
- "cell_type": "code",
466
- "execution_count": null,
467
- "metadata": {
468
-
469
- },
470
- "outputs": [
471
-
472
- ],
473
- "source": [
474
- "from transformers.trainer_utils import get_last_checkpoint\n",
475
- "\n",
476
- "last_checkpoint = None\n",
477
- "if os.path.isdir(DRIVE_OUTPUT_DIR):\n",
478
- " last_checkpoint = get_last_checkpoint(DRIVE_OUTPUT_DIR)\n",
479
- " if last_checkpoint:\n",
480
- " print(\"Resuming from checkpoint:\", last_checkpoint)\n",
481
- "\n",
482
- "trainer.train(resume_from_checkpoint=last_checkpoint)"
483
- ]
484
- },
485
- {
486
- "cell_type": "markdown",
487
- "metadata": {
488
-
489
- },
490
- "source": [
491
- "## 12. Evaluate on the held-out test split"
492
- ]
493
- },
494
- {
495
- "cell_type": "code",
496
- "execution_count": null,
497
- "metadata": {
498
-
499
- },
500
- "outputs": [
501
-
502
- ],
503
- "source": [
504
- "test_metrics = trainer.evaluate(\n",
505
- " eval_dataset=vectorized_datasets[\"test\"],\n",
506
- " metric_key_prefix=\"test\",\n",
507
- ")\n",
508
- "print(test_metrics)"
509
- ]
510
- },
511
- {
512
- "cell_type": "code",
513
- "execution_count": null,
514
- "metadata": {
515
-
516
- },
517
- "outputs": [
518
-
519
- ],
520
- "source": [
521
- "import pandas as pd\n",
522
- "from sklearn.metrics import classification_report\n",
523
- "\n",
524
- "predictions = trainer.predict(vectorized_datasets[\"test\"])\n",
525
- "pred_ids = predictions.predictions\n",
526
- "label_ids = predictions.label_ids\n",
527
- "label_ids[label_ids == -100] = tokenizer.pad_token_id\n",
528
- "\n",
529
- "pred_str = [s.strip() for s in tokenizer.batch_decode(pred_ids, skip_special_tokens=True)]\n",
530
- "label_str = [s.strip() for s in tokenizer.batch_decode(label_ids, skip_special_tokens=True)]\n",
531
- "\n",
532
- "df = pd.DataFrame({\"reference\": label_str, \"prediction\": pred_str})\n",
533
- "df[\"correct\"] = df[\"reference\"] == df[\"prediction\"]\n",
534
- "print(f\"Overall test exact-match accuracy: {df[\u0027correct\u0027].mean() * 100:.2f}%\\n\")\n",
535
- "print(\"Per-letter accuracy:\")\n",
536
- "print(df.groupby(\"reference\")[\"correct\"].mean().sort_values().to_string())"
537
- ]
538
- },
539
- {
540
- "cell_type": "markdown",
541
- "metadata": {
542
-
543
- },
544
- "source": [
545
- "## 13. Save the final model + processor\n",
546
- "\n",
547
- "Saved to Drive so it persists after the Colab runtime is recycled."
548
- ]
549
- },
550
- {
551
- "cell_type": "code",
552
- "execution_count": null,
553
- "metadata": {
554
-
555
- },
556
- "outputs": [
557
-
558
- ],
559
- "source": [
560
- "FINAL_MODEL_DIR = f\"{DRIVE_OUTPUT_DIR}/final_model\"\n",
561
- "trainer.save_model(FINAL_MODEL_DIR)\n",
562
- "processor.save_pretrained(FINAL_MODEL_DIR)\n",
563
- "print(\"Saved final model to\", FINAL_MODEL_DIR)"
564
- ]
565
- },
566
- {
567
- "cell_type": "markdown",
568
- "metadata": {
569
-
570
- },
571
- "source": [
572
- "## 14. Inference\n",
573
- "\n",
574
- "Loads the saved model back (as a fresh consumer would) and runs it on a few test-set clips."
575
- ]
576
- },
577
- {
578
- "cell_type": "code",
579
- "execution_count": null,
580
- "metadata": {
581
-
582
- },
583
- "outputs": [
584
-
585
- ],
586
- "source": [
587
- "inference_processor = WhisperProcessor.from_pretrained(FINAL_MODEL_DIR)\n",
588
- "inference_model = WhisperForConditionalGeneration.from_pretrained(FINAL_MODEL_DIR).to(DEVICE)\n",
589
- "inference_model.eval()\n",
590
- "\n",
591
- "\n",
592
- "def transcribe_letter(audio_array, sampling_rate=16000):\n",
593
- " inputs = inference_processor(\n",
594
- " audio_array, sampling_rate=sampling_rate, return_tensors=\"pt\"\n",
595
- " ).input_features.to(DEVICE)\n",
596
- " with torch.no_grad():\n",
597
- " predicted_ids = inference_model.generate(\n",
598
- " inputs, language=LANGUAGE, task=TASK, max_new_tokens=8\n",
599
- " )\n",
600
- " return inference_processor.batch_decode(predicted_ids, skip_special_tokens=True)[0].strip()\n",
601
- "\n",
602
- "\n",
603
- "sample_indices = random.sample(range(len(raw_datasets[\"test\"])), k=5)\n",
604
- "for idx in sample_indices:\n",
605
- " example = raw_datasets[\"test\"][idx]\n",
606
- " true_text = example[\"transcription\"]\n",
607
- " true_label = example[\"label\"]\n",
608
- " predicted = transcribe_letter(example[\"audio\"][\"array\"], example[\"audio\"][\"sampling_rate\"])\n",
609
- " print(f\"true={true_text!r} pred={predicted!r} label={true_label!r}\")"
610
- ]
611
- },
612
- {
613
- "cell_type": "markdown",
614
- "metadata": {
615
-
616
- },
617
- "source": [
618
- "## 15. (Optional) Push to the Hugging Face Hub\n",
619
- "\n",
620
- "Run this cell if you want the model hosted on the Hub for easy reuse/deployment. Requires\n",
621
- "`huggingface-cli login` or a token cell first."
622
- ]
623
- },
624
- {
625
- "cell_type": "code",
626
- "execution_count": null,
627
- "metadata": {
628
-
629
- },
630
- "outputs": [
631
-
632
- ],
633
- "source": [
634
- "PUSH_TO_HUB = False\n",
635
- "HUB_MODEL_ID = \"your-username/whisper-small-arabic-letters\"\n",
636
- "\n",
637
- "if PUSH_TO_HUB:\n",
638
- " from huggingface_hub import notebook_login\n",
639
- "\n",
640
- " notebook_login()\n",
641
- " inference_model.push_to_hub(HUB_MODEL_ID)\n",
642
- " inference_processor.push_to_hub(HUB_MODEL_ID)\n",
643
- " print(\"Pushed to https://huggingface.co/\" + HUB_MODEL_ID)\n",
644
- "else:\n",
645
- " print(\"Skipped (PUSH_TO_HUB=False)\")"
646
- ]
647
- },
648
- {
649
- "cell_type": "markdown",
650
- "metadata": {
651
-
652
- },
653
- "source": [
654
- "## Notes / production next steps\n",
655
- "\n",
656
- "- **Resuming after disconnect:** rerun cells 1-14 in order; the training cell auto-detects the latest\n",
657
- " checkpoint under `DRIVE_OUTPUT_DIR` and continues instead of restarting.\n",
658
- "- **Faster/lighter inference:** convert the final model to CTranslate2 (`ct2-transformers-converter`) or\n",
659
- " ONNX/`optimum` for lower-latency serving than raw `transformers.generate`.\n",
660
- "- **Smaller footprint:** if `whisper-small` is too heavy for your deployment target, swap\n",
661
- " `MODEL_CHECKPOINT` to `openai/whisper-base` or `openai/whisper-tiny` and rerun from cell 5 -- no other\n",
662
- " code changes needed.\n",
663
- "- **Monitoring:** `tensorboard --logdir \u003cDRIVE_OUTPUT_DIR\u003e/logs` (or `%load_ext tensorboard` +\n",
664
- " `%tensorboard --logdir ...` in a cell) to watch loss/WER curves live during training."
665
- ]
666
- }
667
- ],
668
- "metadata": {
669
- "accelerator": "GPU",
670
- "colab": {
671
- "provenance": [
672
-
673
- ],
674
- "gpuType": "T4"
675
- },
676
- "kernelspec": {
677
- "display_name": "Python 3",
678
- "name": "python3"
679
- },
680
- "language_info": {
681
- "name": "python"
682
- }
683
- },
684
- "nbformat": 4,
685
- "nbformat_minor": 5
686
  }
 
1
  {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# Fine-tune Whisper (small) on Arabic Letter Pronunciation\n",
8
+ "\n",
9
+ "Fine-tunes `openai/whisper-small` to transcribe isolated Arabic letter audio clips (28 letters, ~22k one-second\n",
10
+ "clips, `whisper_dataset/{train,validation,test}` in HuggingFace `audiofolder` format).\n",
11
+ "\n",
12
+ "**Pipeline:** install deps -> mount Drive -> unzip dataset -> load `datasets` -> preprocess audio/text ->\n",
13
+ "fine-tune with `Seq2SeqTrainer` (checkpointing to Drive, early stopping, mixed precision) -> evaluate\n",
14
+ "(WER + per-letter exact-match accuracy) -> save/export final model -> run inference.\n",
15
+ "\n",
16
+ "**Before running:** upload `whisper_dataset.zip` to your Google Drive and set `DRIVE_ZIP_PATH` in the\n",
17
+ "\"Configuration\" cell below. Runtime -> Change runtime type -> GPU (T4 is sufficient)."
18
+ ]
19
+ },
20
+ {
21
+ "cell_type": "code",
22
+ "execution_count": null,
23
+ "metadata": {},
24
+ "outputs": [],
25
+ "source": [
26
+ "!nvidia-smi"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "markdown",
31
+ "metadata": {},
32
+ "source": [
33
+ "## 1. Install dependencies"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": null,
39
+ "metadata": {},
40
+ "outputs": [],
41
+ "source": [
42
+ "!pip install -q \"transformers==4.44.2\" \"datasets==2.21.0\" \"accelerate==0.34.2\" \\\n",
43
+ " \"evaluate==0.4.3\" \"jiwer==3.0.4\" \"soundfile==0.12.1\" \"librosa==0.10.2.post1\" \\\n",
44
+ " \"tensorboard==2.17.1\""
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": null,
50
+ "metadata": {},
51
+ "outputs": [],
52
+ "source": [
53
+ "import os\n",
54
+ "import random\n",
55
+ "import shutil\n",
56
+ "from dataclasses import dataclass\n",
57
+ "from pathlib import Path\n",
58
+ "from typing import Any, Dict, List, Union\n",
59
+ "\n",
60
+ "import numpy as np\n",
61
+ "import torch\n",
62
+ "from datasets import Audio, load_dataset\n",
63
+ "from transformers import (\n",
64
+ " EarlyStoppingCallback,\n",
65
+ " Seq2SeqTrainer,\n",
66
+ " Seq2SeqTrainingArguments,\n",
67
+ " WhisperForConditionalGeneration,\n",
68
+ " WhisperProcessor,\n",
69
+ ")\n",
70
+ "\n",
71
+ "SEED = 42\n",
72
+ "random.seed(SEED)\n",
73
+ "np.random.seed(SEED)\n",
74
+ "torch.manual_seed(SEED)\n",
75
+ "\n",
76
+ "DEVICE = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
77
+ "print(f\"Using device: {DEVICE}\")"
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "markdown",
82
+ "metadata": {},
83
+ "source": [
84
+ "## 2. Configuration & mount Google Drive\n",
85
+ "\n",
86
+ "Set `DRIVE_ZIP_PATH` to wherever you uploaded `whisper_dataset.zip` in your Drive. Checkpoints and the\n",
87
+ "final model are written under `DRIVE_OUTPUT_DIR` so training survives Colab disconnects -- rerunning the\n",
88
+ "notebook will auto-resume from the latest checkpoint."
89
+ ]
90
+ },
91
+ {
92
+ "cell_type": "code",
93
+ "execution_count": null,
94
+ "metadata": {},
95
+ "outputs": [],
96
+ "source": [
97
+ "from google.colab import drive\n",
98
+ "\n",
99
+ "drive.mount(\"/content/drive\")\n",
100
+ "\n",
101
+ "# --- Edit these two paths for your Drive layout ---\n",
102
+ "DRIVE_ZIP_PATH = \"/content/drive/MyDrive/datasets/whisper_dataset.zip\"\n",
103
+ "DRIVE_OUTPUT_DIR = \"/content/drive/MyDrive/arabic_whisper_letters\"\n",
104
+ "# ----------------------------------------------------\n",
105
+ "\n",
106
+ "LOCAL_DATA_DIR = \"/content/whisper_dataset\"\n",
107
+ "MODEL_CHECKPOINT = \"openai/whisper-small\"\n",
108
+ "LANGUAGE = \"arabic\"\n",
109
+ "TASK = \"transcribe\"\n",
110
+ "\n",
111
+ "os.makedirs(DRIVE_OUTPUT_DIR, exist_ok=True)\n",
112
+ "assert os.path.exists(DRIVE_ZIP_PATH), (\n",
113
+ " f\"{DRIVE_ZIP_PATH} not found -- upload whisper_dataset.zip to your Drive and update DRIVE_ZIP_PATH.\"\n",
114
+ ")\n",
115
+ "print(\"Drive mounted. Zip found at:\", DRIVE_ZIP_PATH)"
116
+ ]
117
+ },
118
+ {
119
+ "cell_type": "markdown",
120
+ "metadata": {},
121
+ "source": [
122
+ "## 3. Unzip the dataset to local (fast) disk\n",
123
+ "\n",
124
+ "Extracting to `/content` instead of reading straight from Drive avoids the slow, flaky I/O of training\n",
125
+ "against a mounted Drive folder."
126
+ ]
127
+ },
128
+ {
129
+ "cell_type": "code",
130
+ "execution_count": null,
131
+ "metadata": {},
132
+ "outputs": [],
133
+ "source": [
134
+ "if not os.path.isdir(LOCAL_DATA_DIR):\n",
135
+ " print(\"Extracting dataset (one-time)...\")\n",
136
+ " shutil.unpack_archive(DRIVE_ZIP_PATH, \"/content\")\n",
137
+ " print(\"Done.\")\n",
138
+ "else:\n",
139
+ " print(\"Dataset already extracted at\", LOCAL_DATA_DIR)\n",
140
+ "\n",
141
+ "for split in (\"train\", \"validation\", \"test\"):\n",
142
+ " n = sum(1 for _ in open(f\"{LOCAL_DATA_DIR}/{split}/metadata.csv\", encoding=\"utf-8\")) - 1\n",
143
+ " print(f\"{split}: {n} rows\")"
144
+ ]
145
+ },
146
+ {
147
+ "cell_type": "markdown",
148
+ "metadata": {},
149
+ "source": [
150
+ "## 4. Load the dataset"
151
+ ]
152
+ },
153
+ {
154
+ "cell_type": "code",
155
+ "execution_count": null,
156
+ "metadata": {},
157
+ "outputs": [],
158
+ "source": [
159
+ "raw_datasets = load_dataset(\"audiofolder\", data_dir=LOCAL_DATA_DIR)\n",
160
+ "print(raw_datasets)\n",
161
+ "\n",
162
+ "# sanity check: every split should cover all 28 letters\n",
163
+ "for split in raw_datasets:\n",
164
+ " labels = set(raw_datasets[split][\"label\"])\n",
165
+ " print(f\"{split}: {len(labels)} unique letters, {len(raw_datasets[split])} examples\")\n",
166
+ "\n",
167
+ "print(\"\\nSample example:\")\n",
168
+ "example = raw_datasets[\"train\"][0]\n",
169
+ "print({k: v for k, v in example.items() if k != \"audio\"})"
170
+ ]
171
+ },
172
+ {
173
+ "cell_type": "markdown",
174
+ "metadata": {},
175
+ "source": [
176
+ "## 5. Load the Whisper processor (feature extractor + tokenizer)"
177
+ ]
178
+ },
179
+ {
180
+ "cell_type": "code",
181
+ "execution_count": null,
182
+ "metadata": {},
183
+ "outputs": [],
184
+ "source": [
185
+ "processor = WhisperProcessor.from_pretrained(MODEL_CHECKPOINT, language=LANGUAGE, task=TASK)\n",
186
+ "feature_extractor = processor.feature_extractor\n",
187
+ "tokenizer = processor.tokenizer"
188
+ ]
189
+ },
190
+ {
191
+ "cell_type": "markdown",
192
+ "metadata": {},
193
+ "source": [
194
+ "## 6. Preprocess: resample audio to 16kHz, extract log-mel features, tokenize labels"
195
+ ]
196
+ },
197
+ {
198
+ "cell_type": "code",
199
+ "execution_count": null,
200
+ "metadata": {},
201
+ "outputs": [],
202
+ "source": [
203
+ "raw_datasets = raw_datasets.cast_column(\"audio\", Audio(sampling_rate=16000))\n",
204
+ "\n",
205
+ "\n",
206
+ "def prepare_batch(batch):\n",
207
+ " audio = batch[\"audio\"]\n",
208
+ " batch[\"input_features\"] = feature_extractor(\n",
209
+ " audio[\"array\"], sampling_rate=audio[\"sampling_rate\"]\n",
210
+ " ).input_features[0]\n",
211
+ " batch[\"labels\"] = tokenizer(batch[\"transcription\"]).input_ids\n",
212
+ " return batch\n",
213
+ "\n",
214
+ "\n",
215
+ "vectorized_datasets = raw_datasets.map(\n",
216
+ " prepare_batch,\n",
217
+ " remove_columns=raw_datasets[\"train\"].column_names,\n",
218
+ " num_proc=2,\n",
219
+ " desc=\"Extracting features\",\n",
220
+ ")"
221
+ ]
222
+ },
223
+ {
224
+ "cell_type": "markdown",
225
+ "metadata": {},
226
+ "source": [
227
+ "## 7. Data collator (pads audio features and label sequences separately)"
228
+ ]
229
+ },
230
+ {
231
+ "cell_type": "code",
232
+ "execution_count": null,
233
+ "metadata": {},
234
+ "outputs": [],
235
+ "source": [
236
+ "@dataclass\n",
237
+ "class DataCollatorSpeechSeq2SeqWithPadding:\n",
238
+ " processor: Any\n",
239
+ "\n",
240
+ " def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) -> Dict[str, torch.Tensor]:\n",
241
+ " input_features = [{\"input_features\": f[\"input_features\"]} for f in features]\n",
242
+ " batch = self.processor.feature_extractor.pad(input_features, return_tensors=\"pt\")\n",
243
+ "\n",
244
+ " label_features = [{\"input_ids\": f[\"labels\"]} for f in features]\n",
245
+ " labels_batch = self.processor.tokenizer.pad(label_features, return_tensors=\"pt\")\n",
246
+ " labels = labels_batch[\"input_ids\"].masked_fill(labels_batch.attention_mask.ne(1), -100)\n",
247
+ "\n",
248
+ " if (labels[:, 0] == self.processor.tokenizer.bos_token_id).all().cpu().item():\n",
249
+ " labels = labels[:, 1:]\n",
250
+ "\n",
251
+ " batch[\"labels\"] = labels\n",
252
+ " return batch\n",
253
+ "\n",
254
+ "\n",
255
+ "data_collator = DataCollatorSpeechSeq2SeqWithPadding(processor=processor)"
256
+ ]
257
+ },
258
+ {
259
+ "cell_type": "markdown",
260
+ "metadata": {},
261
+ "source": [
262
+ "## 8. Load the model"
263
+ ]
264
+ },
265
+ {
266
+ "cell_type": "code",
267
+ "execution_count": null,
268
+ "metadata": {},
269
+ "outputs": [],
270
+ "source": [
271
+ "model = WhisperForConditionalGeneration.from_pretrained(MODEL_CHECKPOINT)\n",
272
+ "model.generation_config.language = LANGUAGE\n",
273
+ "model.generation_config.task = TASK\n",
274
+ "model.generation_config.forced_decoder_ids = None\n",
275
+ "model.config.suppress_tokens = []\n",
276
+ "model.config.use_cache = False # required with gradient checkpointing"
277
+ ]
278
+ },
279
+ {
280
+ "cell_type": "markdown",
281
+ "metadata": {},
282
+ "source": [
283
+ "## 9. Metrics: word error rate + per-letter exact-match accuracy\n",
284
+ "\n",
285
+ "WER is the standard ASR metric; exact-match accuracy is more interpretable here since every label is a\n",
286
+ "single letter, so it doubles as classification accuracy over the 28 letters."
287
+ ]
288
+ },
289
+ {
290
+ "cell_type": "code",
291
+ "execution_count": null,
292
+ "metadata": {},
293
+ "outputs": [],
294
+ "source": [
295
+ "import evaluate\n",
296
+ "\n",
297
+ "wer_metric = evaluate.load(\"wer\")\n",
298
+ "\n",
299
+ "\n",
300
+ "def compute_metrics(pred):\n",
301
+ " pred_ids = pred.predictions\n",
302
+ " label_ids = pred.label_ids\n",
303
+ " label_ids[label_ids == -100] = tokenizer.pad_token_id\n",
304
+ "\n",
305
+ " pred_str = tokenizer.batch_decode(pred_ids, skip_special_tokens=True)\n",
306
+ " label_str = tokenizer.batch_decode(label_ids, skip_special_tokens=True)\n",
307
+ "\n",
308
+ " wer = 100 * wer_metric.compute(predictions=pred_str, references=label_str)\n",
309
+ " accuracy = 100 * np.mean(\n",
310
+ " [p.strip() == l.strip() for p, l in zip(pred_str, label_str)]\n",
311
+ " )\n",
312
+ " return {\"wer\": wer, \"accuracy\": accuracy}"
313
+ ]
314
+ },
315
+ {
316
+ "cell_type": "markdown",
317
+ "metadata": {},
318
+ "source": [
319
+ "## 10. Training arguments\n",
320
+ "\n",
321
+ "Checkpoints go to `DRIVE_OUTPUT_DIR` so a disconnect does not lose progress. `load_best_model_at_end` +\n",
322
+ "`EarlyStoppingCallback` (next cell) stop training once WER stops improving instead of burning a fixed\n",
323
+ "budget of steps."
324
+ ]
325
+ },
326
+ {
327
+ "cell_type": "code",
328
+ "execution_count": null,
329
+ "metadata": {},
330
+ "outputs": [],
331
+ "source": "training_args = Seq2SeqTrainingArguments(\n output_dir=DRIVE_OUTPUT_DIR,\n per_device_train_batch_size=16,\n gradient_accumulation_steps=2,\n per_device_eval_batch_size=16,\n learning_rate=1e-5,\n warmup_steps=500,\n num_train_epochs=10,\n gradient_checkpointing=True,\n fp16=(DEVICE == \"cuda\"),\n eval_strategy=\"steps\",\n eval_steps=500,\n save_strategy=\"steps\",\n save_steps=500,\n save_total_limit=3,\n logging_steps=50,\n logging_dir=f\"{DRIVE_OUTPUT_DIR}/logs\",\n report_to=[\"tensorboard\"],\n predict_with_generate=True,\n generation_max_length=16,\n load_best_model_at_end=True,\n metric_for_best_model=\"wer\",\n greater_is_better=False,\n dataloader_num_workers=2,\n seed=SEED,\n)"
332
+ },
333
+ {
334
+ "cell_type": "code",
335
+ "execution_count": null,
336
+ "metadata": {},
337
+ "outputs": [],
338
+ "source": [
339
+ "trainer = Seq2SeqTrainer(\n",
340
+ " args=training_args,\n",
341
+ " model=model,\n",
342
+ " train_dataset=vectorized_datasets[\"train\"],\n",
343
+ " eval_dataset=vectorized_datasets[\"validation\"],\n",
344
+ " data_collator=data_collator,\n",
345
+ " compute_metrics=compute_metrics,\n",
346
+ " tokenizer=processor.feature_extractor,\n",
347
+ " callbacks=[EarlyStoppingCallback(early_stopping_patience=5)],\n",
348
+ ")"
349
+ ]
350
+ },
351
+ {
352
+ "cell_type": "markdown",
353
+ "metadata": {},
354
+ "source": [
355
+ "## 11. Train\n",
356
+ "\n",
357
+ "Auto-resumes from the latest checkpoint in `DRIVE_OUTPUT_DIR` if one exists (e.g. after a Colab\n",
358
+ "disconnect) -- rerun this cell to continue rather than restarting from scratch."
359
+ ]
360
+ },
361
+ {
362
+ "cell_type": "code",
363
+ "execution_count": null,
364
+ "metadata": {},
365
+ "outputs": [],
366
+ "source": [
367
+ "from transformers.trainer_utils import get_last_checkpoint\n",
368
+ "\n",
369
+ "last_checkpoint = None\n",
370
+ "if os.path.isdir(DRIVE_OUTPUT_DIR):\n",
371
+ " last_checkpoint = get_last_checkpoint(DRIVE_OUTPUT_DIR)\n",
372
+ " if last_checkpoint:\n",
373
+ " print(\"Resuming from checkpoint:\", last_checkpoint)\n",
374
+ "\n",
375
+ "trainer.train(resume_from_checkpoint=last_checkpoint)"
376
+ ]
377
+ },
378
+ {
379
+ "cell_type": "markdown",
380
+ "metadata": {},
381
+ "source": [
382
+ "## 12. Evaluate on the held-out test split"
383
+ ]
384
+ },
385
+ {
386
+ "cell_type": "code",
387
+ "execution_count": null,
388
+ "metadata": {},
389
+ "outputs": [],
390
+ "source": [
391
+ "test_metrics = trainer.evaluate(\n",
392
+ " eval_dataset=vectorized_datasets[\"test\"],\n",
393
+ " metric_key_prefix=\"test\",\n",
394
+ ")\n",
395
+ "print(test_metrics)"
396
+ ]
397
+ },
398
+ {
399
+ "cell_type": "code",
400
+ "execution_count": null,
401
+ "metadata": {},
402
+ "outputs": [],
403
+ "source": [
404
+ "import pandas as pd\n",
405
+ "from sklearn.metrics import classification_report\n",
406
+ "\n",
407
+ "predictions = trainer.predict(vectorized_datasets[\"test\"])\n",
408
+ "pred_ids = predictions.predictions\n",
409
+ "label_ids = predictions.label_ids\n",
410
+ "label_ids[label_ids == -100] = tokenizer.pad_token_id\n",
411
+ "\n",
412
+ "pred_str = [s.strip() for s in tokenizer.batch_decode(pred_ids, skip_special_tokens=True)]\n",
413
+ "label_str = [s.strip() for s in tokenizer.batch_decode(label_ids, skip_special_tokens=True)]\n",
414
+ "\n",
415
+ "df = pd.DataFrame({\"reference\": label_str, \"prediction\": pred_str})\n",
416
+ "df[\"correct\"] = df[\"reference\"] == df[\"prediction\"]\n",
417
+ "print(f\"Overall test exact-match accuracy: {df['correct'].mean() * 100:.2f}%\\n\")\n",
418
+ "print(\"Per-letter accuracy:\")\n",
419
+ "print(df.groupby(\"reference\")[\"correct\"].mean().sort_values().to_string())"
420
+ ]
421
+ },
422
+ {
423
+ "cell_type": "markdown",
424
+ "metadata": {},
425
+ "source": [
426
+ "## 13. Save the final model + processor\n",
427
+ "\n",
428
+ "Saved to Drive so it persists after the Colab runtime is recycled."
429
+ ]
430
+ },
431
+ {
432
+ "cell_type": "code",
433
+ "execution_count": null,
434
+ "metadata": {},
435
+ "outputs": [],
436
+ "source": [
437
+ "FINAL_MODEL_DIR = f\"{DRIVE_OUTPUT_DIR}/final_model\"\n",
438
+ "trainer.save_model(FINAL_MODEL_DIR)\n",
439
+ "processor.save_pretrained(FINAL_MODEL_DIR)\n",
440
+ "print(\"Saved final model to\", FINAL_MODEL_DIR)"
441
+ ]
442
+ },
443
+ {
444
+ "cell_type": "markdown",
445
+ "metadata": {},
446
+ "source": [
447
+ "## 14. Inference\n",
448
+ "\n",
449
+ "Loads the saved model back (as a fresh consumer would) and runs it on a few test-set clips."
450
+ ]
451
+ },
452
+ {
453
+ "cell_type": "code",
454
+ "execution_count": null,
455
+ "metadata": {},
456
+ "outputs": [],
457
+ "source": "inference_processor = WhisperProcessor.from_pretrained(FINAL_MODEL_DIR)\ninference_model = WhisperForConditionalGeneration.from_pretrained(FINAL_MODEL_DIR).to(DEVICE)\ninference_model.eval()\n\n\ndef transcribe_letter(audio_array, sampling_rate=16000):\n inputs = inference_processor(\n audio_array, sampling_rate=sampling_rate, return_tensors=\"pt\"\n ).input_features.to(DEVICE)\n with torch.no_grad():\n predicted_ids = inference_model.generate(\n inputs, language=LANGUAGE, task=TASK, max_new_tokens=16\n )\n return inference_processor.batch_decode(predicted_ids, skip_special_tokens=True)[0].strip()\n\n\nsample_indices = random.sample(range(len(raw_datasets[\"test\"])), k=5)\nfor idx in sample_indices:\n example = raw_datasets[\"test\"][idx]\n true_text = example[\"transcription\"]\n true_label = example[\"label\"]\n predicted = transcribe_letter(example[\"audio\"][\"array\"], example[\"audio\"][\"sampling_rate\"])\n print(f\"true={true_text!r} pred={predicted!r} label={true_label!r}\")"
458
+ },
459
+ {
460
+ "cell_type": "markdown",
461
+ "metadata": {},
462
+ "source": [
463
+ "## 15. (Optional) Push to the Hugging Face Hub\n",
464
+ "\n",
465
+ "Run this cell if you want the model hosted on the Hub for easy reuse/deployment. Requires\n",
466
+ "`huggingface-cli login` or a token cell first."
467
+ ]
468
+ },
469
+ {
470
+ "cell_type": "code",
471
+ "execution_count": null,
472
+ "metadata": {},
473
+ "outputs": [],
474
+ "source": [
475
+ "PUSH_TO_HUB = False\n",
476
+ "HUB_MODEL_ID = \"your-username/whisper-small-arabic-letters\"\n",
477
+ "\n",
478
+ "if PUSH_TO_HUB:\n",
479
+ " from huggingface_hub import notebook_login\n",
480
+ "\n",
481
+ " notebook_login()\n",
482
+ " inference_model.push_to_hub(HUB_MODEL_ID)\n",
483
+ " inference_processor.push_to_hub(HUB_MODEL_ID)\n",
484
+ " print(\"Pushed to https://huggingface.co/\" + HUB_MODEL_ID)\n",
485
+ "else:\n",
486
+ " print(\"Skipped (PUSH_TO_HUB=False)\")"
487
+ ]
488
+ },
489
+ {
490
+ "cell_type": "markdown",
491
+ "metadata": {},
492
+ "source": [
493
+ "## Notes / production next steps\n",
494
+ "\n",
495
+ "- **Resuming after disconnect:** rerun cells 1-14 in order; the training cell auto-detects the latest\n",
496
+ " checkpoint under `DRIVE_OUTPUT_DIR` and continues instead of restarting.\n",
497
+ "- **Faster/lighter inference:** convert the final model to CTranslate2 (`ct2-transformers-converter`) or\n",
498
+ " ONNX/`optimum` for lower-latency serving than raw `transformers.generate`.\n",
499
+ "- **Smaller footprint:** if `whisper-small` is too heavy for your deployment target, swap\n",
500
+ " `MODEL_CHECKPOINT` to `openai/whisper-base` or `openai/whisper-tiny` and rerun from cell 5 -- no other\n",
501
+ " code changes needed.\n",
502
+ "- **Monitoring:** `tensorboard --logdir <DRIVE_OUTPUT_DIR>/logs` (or `%load_ext tensorboard` +\n",
503
+ " `%tensorboard --logdir ...` in a cell) to watch loss/WER curves live during training."
504
+ ]
505
+ }
506
+ ],
507
+ "metadata": {
508
+ "accelerator": "GPU",
509
+ "colab": {
510
+ "provenance": [],
511
+ "gpuType": "T4"
512
+ },
513
+ "kernelspec": {
514
+ "display_name": "Python 3",
515
+ "name": "python3"
516
+ },
517
+ "language_info": {
518
+ "name": "python"
519
+ }
520
+ },
521
+ "nbformat": 4,
522
+ "nbformat_minor": 5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
523
  }