Batch normalization normalizes activations within each mini-batch to stabilize and accelerate training.
Algorithm (for each feature dimension in a layer):
- Compute mini-batch mean:
- Compute mini-batch variance:
- Normalize:
- Scale and shift (learnable):
Placement: typically after the linear transformation, before the activation function.
Why it helps:
- Reduces internal covariate shift — each layer sees stable input distributions
- Allows higher learning rates without divergence
- Acts as implicit Regularization (mini-batch noise)
- Smooths the loss landscape → easier optimization
At inference: use running averages of and computed during training (not batch statistics).
Variants:
- Layer Normalization — normalizes across features (not batch). Used in transformers because it works with variable sequence lengths and doesn't depend on batch size
- Group Normalization — between BatchNorm and LayerNorm
- RMSNorm — simplified LayerNorm without centering. Used in modern LLMs
See also: Weight Initialization, Backpropagation, Residual Connections