Overfitting & Regularization
Learning patterns, not memorizing examples
A model that memorizes training data instead of learning patterns catastrophically fails on new data. Regularization — data, capacity, weight shaping — is the discipline between 'underfits' and 'overfits'.
What you will learn
- Diagnose overfitting vs underfitting from loss curves
- Apply capacity, weight decay, dropout and early stopping
- Detect surprise — high-certainty wrong answers
What is this?
Overfitting is when a model captures noise and idiosyncrasies of training data rather than the true signal — great training scores, poor test scores. Underfitting is the reverse: too simple to learn the signal. Regularization trades small training-score losses for much better generalization: more/better data, less capacity, weight decay, dropout, augmentation and early stopping.
Why do you need it?
- Production models face data they've never seen; memorization collapses exactly there.
- The train/test gap is the single most honest quality signal you have.
- Deep models are prone to memorization at scale — regularization is not optional there.
- Understanding it explains why fine-tuning small models on little data fails hard.
Mental model
Cramming for a test
Overfitting
A student who memorizes the exact practice questions (training) freezes on a reworded exam (test). A student who honestly learned the rules generalizes. Training data is your practice set; the real world rewrites the exam.
How it works
- Watch the gap: train loss down, validation/test loss up = overfitting; both high = underfitting.
- Weight decay (L2) shrinks weights toward noise-free, simpler functions.
- Dropout randomly zeroes neurons during training, forcing redundancy and de-correlation.
- Early stopping ends training the moment validation stops improving.
- More/better data and augmentation are the strongest regularizers of all.
The bias-variance playground.
In production
- A classifier uses weight decay + early stopping, gated on the validation plateau.
- A vision stack uses augmentation so the model never overfits viewpoint/lighting noise.
- Fine-tuning small LoRA adapters applies dropout at the projection so they generalize to new prompts.
Best practices
- Read the train/val gap every run; it decides everything.
- Prefer data-quality and capacity fixes before penalty tricks.
- Tune dropout/decay on validation, then re-verify on reserved test.
- Early-stop on validation, and re-check final performance on the frozen test set.
Common mistakes
- Regularizing so hard the model underfits — the train/val both rising gives it away.
- Applying dropout at inference without toggling it off.
- Tuning on test until the gap report stops being honest.
Common issues
Validation reliability worse than a smaller modelOversized capacity for the data with no regularization
Shrink capacity or strengthen decay/dropout and re-split carefully.
Regularization kills all signalsPenalties too strong relative to data signal
Reduce weight decay, check drop rate, and favor more data first.
Early stopping fires too earlyValidation noisy around a still-improving region
Use patience (N epochs) instead of the first flat step.
Debugging tips
- Train ~0 but test collapsing — look at leakage, then capacity, then regularization.
- Validation plateau then rise — classic overfit saddle; early-stop there.
- High-confidence wrong answers on OOD inputs — a typical cap of memorized models.
Interview checkpoint
Quick quiz
Which signature best indicates overfitting?
Dropout should be active at inference time.