Batch Normalization
Intuition
Layer inputs drift as earlier layers learn. Batch normalisation standardises each feature using the current mini-batch's mean and variance, then lets the network re-scale and re-shift with learned parameters — making training faster and less sensitive to initialisation.
Precise explanation
For a batch (n, d), per feature:
Running statistics for evaluation (PyTorch-style momentum, D2L describes the same idea):
where the running variance uses the unbiased batch variance (as PyTorch does). Evaluation uses the running statistics, so a single example gives a deterministic output. Initial values: , , , .
Worked example
x = [[1], [3]]: μ = 2, σ² = 1 → x̂ ≈ [−1, 1] (ε small). Running mean after one step with m = 0.1: 0.2; running var: 0.9·1 + 0.1·2 = 1.1 (unbiased var = 2).
Common mistakes
- Using batch statistics at evaluation time.
- Normalising across features instead of across the batch (that is layer norm).
- Updating running statistics during evaluation.
Why this matters
Batch norm is common in CNNs; its train/eval distinction appears again in dropout and in federated settings where client batch statistics differ.
Library implementation
torch.nn.BatchNorm1d(n_features, momentum=0.1, eps=1e-5) uses the same conventions: batch
statistics with the biased variance in training mode, running averages updated with the
unbiased variance, and running statistics in evaluation mode (model.eval()).
References
- Dive into Deep Learning — Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola (
S013)