Skip to content

Notes

Speech ML notes

Concepts

Training paradigms (where the labels come from)

Paradigm Labels Example
Supervised Clean, human-verified transcripts (small: ~1k–10k h) LibriSpeech (960 h)
Weakly supervised Pre-existing, noisy, unverified labels found at scale (subtitles, captions), filtered by heuristics Whisper (680k h web audio)
Self-supervised None; the input is its own target (predict masked frames). Learns representations, needs fine-tuning for the task wav2vec 2.0, HuBERT
Self-training (pseudo-labeling) A teacher model trained on real labels transcribes unlabeled audio; a student trains on those pseudo-labels (filtered by confidence) Noisy Student, Whisper large-v3, Distil-Whisper
  • Weak supervision vs self-training: both use imperfect labels; the first finds them, the second generates them with a model.
  • Self-training ≠ self-supervised: self-training needs a labeled set to train the teacher and learns the actual task.

Transformer encoder-decoder

  • Encoder reads the whole input (e.g. audio features) → one hidden state per position.
  • Decoder input = the target tokens shifted right (starts with a start token). It predicts the next token at each position; causal masking stops it from seeing the future.
  • Teacher forcing: in training the decoder is fed the true previous tokens, not its own predictions. At inference it feeds back its own outputs, one token at a time.
  • The encoder output enters the decoder only through cross-attention: decoder positions are the queries; encoder states are the keys and values.

Speech self-supervised objectives (pre-training, no labels)

  • wav2vec 2.0: mask spans of latent frames; the model must pick the true quantized latent for each masked frame out of distractors (contrastive loss), plus a diversity loss so all codebook entries get used.
  • HuBERT: run k-means on audio features (MFCCs first, later the model’s own layers) to make pseudo-labels, then predict the cluster ID of masked frames with cross-entropy, as in BERT’s MLM.
  • Neither uses text. CTC only appears at fine-tuning, when a linear head over characters is added and trained on transcripts.

CTC limits and the LM fix

  • CTC predicts one character (or blank) per frame, independently of the other frames. Nothing models spelling or word sequences, so outputs come out phonetic (“ther” for “there”).
  • Collapsing repeats and removing blanks is just decoding, not a language model.
  • Fix: beam-search decoding with an n-gram language model. Each candidate transcript is scored as acoustic score + α·LM score + β·word count, so real words and likely word sequences win.
    • KenLM = a library that builds and queries n-gram LMs from a text corpus.
    • pyctcdecode = the beam-search decoder that combines the CTC logits with that LM.

Whisper prefix tokens

  • The decoder always starts with <|startoftranscript|> <|lang|> <|task|> [<|notimestamps|>].
  • generate(language=..., task=...) forces these tokens. If no language is given, Whisper predicts the language token itself (built-in language detection). The task defaults to transcribe.
  • It obeys them because every training label began with the matching prefix.
  • Fine-tuning: labels must carry the same prefix → tokenizer.set_prefix_tokens(language=..., task="transcribe").

Whisper previous-text conditioning (prompting)

  • The decoder is an audio-conditioned LM, so it can also take earlier transcript text as context: <|startofprev|> previous text <|startoftranscript|> <|lang|> <|task|> …. No loss is computed on the previous text.
  • Helps with ambiguous audio: names and rare words seen earlier, homophones, consistent spelling and formatting.
  • Trained with random inclusion (some examples have history, some don’t), so it works without a prompt and the audio stays the main signal instead of being shortcut by the text.
  • Uses: long-form transcription (feed the previous window’s output, condition_on_prev_tokens), and custom prompts for domain vocabulary (prompt_ids).
  • Risk: errors and hallucination loops can carry forward → fall back to a higher temperature or drop the conditioning.
  • Fine-tuning: if your data never includes prompts, the model can lose the ability to use them. Keep random previous-text inclusion if you rely on prompting.

Fine-tuning

Classifier fine-tuning recipe (e.g. DistilHuBERT on GTZAN)

  • Pretrained body + a new, randomly initialized classification head (pooled hidden states → linear → num_labels).
  • Train the whole model, not just the head. Loss = cross-entropy on raw logits (no softmax before the loss).
  • Freeze the CNN feature encoder (freeze_feature_encoder()): it’s low-level, already good, and memory-hungry.
  • Pass num_labels, id2label, label2id so the head size and the predicted label names are right.

Full fine-tune vs frozen features vs LoRA

  • Frozen encoder + learned weighted sum of all layers (SUPERB style): cheapest; different layers hold different info (lower = acoustic/speaker, middle = phonetic, upper = more task-specific).
  • Full fine-tune: best results when you have enough labeled data.
  • LoRA/PEFT: far less memory and small adapters, but low rank limits big shifts (e.g. a new language or very different acoustics). Use higher rank or a full fine-tune there.

Adapters and LoRA

  • Adapters: small trainable modules inserted into a frozen model’s layers. The model adapts to new data without changing the pretrained weights. Freezing the base makes fine-tuning cheaper and less prone to overfitting. Shape: FC down → nonlinearity → FC up, plus a residual.
  • LoRA: learn the weight update as a product of two thin matrices: ΔW = W_A @ W_B, with W_A (in × r) and W_B (r × out). W stays frozen. Forward pass: h = x @ W + alpha · (x @ W_A) @ W_B.
  • Why low rank works: the update a new task needs has low “intrinsic dimension”. A rank-r matrix is a sum of r row patterns, and r = 8–16 usually captures most of the update.
  • Parameter savings: for a 100 × 500 weight, full ΔW = 50,000 values; LoRA with r = 5 = 100·5 + 5·500 = 3,000. Cost grows linearly with r. A smaller r is cheaper but can underfit.
  • Initialisation: W_A random, W_B zeros, so ΔW = 0 at step 0 and training starts from exactly the pretrained model. If both were zero, neither would get a gradient.
  • LoRA vs adapter: both squeeze down and expand back (768 → 8 → 768). LoRA has no nonlinearity and runs in parallel with W. So it can be merged after training (W + W_A @ W_B) and adds no inference cost. A bottleneck adapter can’t be merged this way.
  • Source: Raschka, Parameter-Efficient LLM Finetuning With LoRA

ULMFiT ideas that carry over to speech

  • LR warmup then decay (wav2vec 2.0 uses a tri-stage schedule).
  • Gradual unfreezing: train only the head first (wav2vec 2.0 keeps the transformer frozen for the first N steps), then unfreeze.
  • Discriminative LRs: a lower LR for the pretrained body than for the new head.

Pre-training + self-training are complementary (wav2vec 2.0, Auli / FAIR, 2021)

  • Recipe: self-supervised pretrain on unlabeled audio → CTC fine-tune on a small labeled set → use that model to transcribe (pseudo-label) the unlabeled audio → fine-tune the pretrained model again on the pseudo-labels.
  • Same audio, used twice: LibriLight 60k h is used for pretraining (no text) and again for self-training (with pseudo-transcripts). Pretraining learns how speech sounds; self-training learns which sounds map to which words.
  • Result (10 min labels, LibriSpeech test-other): WER 8.2% → 5.2% = 37% relative reduction, with zero extra human labels. WER is always scored against human transcripts on a held-out test set.
  • Report WER gains as relative, not absolute: small absolute drops at low WER are large.
  • Still holds today: Whisper large-v3 (pseudo-labels from large-v2), Distil-Whisper and Meta’s Omnilingual ASR (2025) all rely on pretraining and/or pseudo-labeling.
  • Use it when: lots of untranscribed in-domain audio, few transcripts → fine-tune on labels, pseudo-label the rest, filter low-confidence outputs, fine-tune again.

Which approach for which situation (as of Nov 2026)

Situation Typical approach Recent examples
High-resource ASR (English, major languages) Large curated supervised data (~0.5M h) + augmentation + pseudo-labels/synthetic data; FastConformer encoder + light decoder Cohere Transcribe (2B, Mar 2026), NVIDIA Parakeet / Canary
Low-resource languages, few labels Self-supervised pretraining + fine-tuning (+ self-training) Meta Omnilingual ASR (7B wav2vec 2.0 on 4.3M h, 1,600+ languages, Nov 2025), MMS
ASR that also understands / follows prompts Speech-LLM: pretrained audio encoder → projector → LLM decoder; staged training (encoder pretrain → align adapter with frozen LLM → SFT → sometimes RL) Qwen3-ASR (Jan 2026), Canary-Qwen-2.5B, Voxtral, NIM4-ASR
Non-ASR tasks (speaker, emotion, diarization) Self-supervised encoders as frozen or fine-tuned features WavLM, HuBERT
Small/fast deployment Distill a big teacher into a student on its pseudo-labels Distil-Whisper

Evaluation

WER normalisation

  • Every dataset writes references in its own style (case, punctuation, “$25” vs “twenty five dollars”, fillers, [noise]). Normalise both predictions and references to one canonical form before WER, so style differences aren’t counted as errors. This is essential for zero-shot evaluation (Whisper’s EnglishTextNormalizer).
  • Key steps: lowercase · strip punctuation and bracketed annotations · standardise numbers and currency · British → American spelling · expand contractions · drop fillers (um, uh).
  • Report both orthographic WER (raw) and normalised WER.
  • Filter out samples whose reference is empty after normalising: WER = (S+D+I)/N and N = 0 divides by zero. Empty predictions are fine (scored as 100% deletions).
  • Caveat: a normaliser tuned while looking at one model’s outputs can flatter that model.

Reading overfitting from training curves

Overfitting sketch

  • Evaluate the validation set every N steps to monitor and pick the best checkpoint; touch the test set once at the end.
  • Train loss → ~0 while eval loss rises = memorising. Eval loss ↑ with WER flat = early warning (over-confidence); eval WER ↑ = overfitting now hurts transcripts → keep the checkpoint at the WER minimum (load_best_model_at_end, metric_for_best_model="wer", early stopping).

Inference

Half precision (fp16 / bf16)

  • What: store weights and activations in 16 bits instead of 32. fp32 keeps about 7 significant digits; fp16 keeps about 3 (max value 65,504); bf16 keeps about 2–3 but has the same range as fp32.
  • Gain: half the memory (whisper-large goes from ~6.2 GB to ~3.1 GB) and roughly 1.5–3× faster on GPU tensor cores.
  • Why WER barely changes (typically within ~0.1 absolute): networks tolerate small noise, and the ~0.05% rounding error per weight averages out across dot products. Decoding is an argmax, so only near-tie tokens flip. Libraries keep softmax and layer norm accumulations in fp32.
  • Training is different: pure fp16 loses tiny updates (lr × grad ≈ 1e-8 rounds away) and small gradients underflow to 0. Use mixed precision instead: fp32 master weights, a 16-bit forward and backward pass, and loss scaling for fp16. Prefer bf16 where supported (no overflow, no loss scaling).
  • Going further: int8/int4 quantization (faster-whisper, whisper.cpp) saves more memory but starts costing a few tenths of a point of WER.