Foundations / Regularization & Generalization
Regularization & Generalization
IntermediateTechniques that prevent overfitting so the model performs well on unseen data.
Bias–variance trade-off
Underfitting (high bias) means the model is too simple; overfitting (high variance) means it memorises training data. Monitor training vs. validation loss to diagnose.
Techniques
λ ≥ 0 controls the L2 penalty, whose gradient is 2λw. This is an objective penalty; decoupled weight decay in AdamW is not generally equivalent to adding it to an adaptive optimizer’s loss.
- L2 weight decay / L1 penalties.
- Dropout — randomly zero activations during training.
- Batch Normalization and Layer Normalization.
- Data augmentation — flips, crops, noise, mixup.
- Early stopping on validation loss.
- Label smoothing.
Interview questions & answers
Q1. How can training and validation curves reveal overfitting?
Answer: Overfitting is suggested when training loss continues to improve while validation loss worsens or the gap between them grows. Consider data augmentation, a smaller model, stronger regularization or early stopping, while checking that the validation set represents the intended deployment data.
Q2. How does dropout behave during training and inference?
Answer: During training, dropout randomly zeros activations. Inverted dropout also scales retained activations to preserve their expected value. During ordinary inference, dropout is disabled and all activations are used; inference should use evaluation mode.
Q3. How does early stopping prevent overfitting?
Answer: Early stopping monitors a validation metric and stops training after it fails to improve for a chosen patience period. Restore the best validation checkpoint rather than automatically taking the last one. Keep the test set out of checkpoint selection.