What is the batch normalisation forward pass for one feature? For a mini-batch of activations with , and , what are the outputs? What changes at inference time, and why do transformers use layer normalisation instead?
Deep learning, Normalisation
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.
What's being asked
Whether you can compute batch statistics by hand, know the difference between training and evaluation, and know which axis each normalisation uses.
Key idea
and . Here and are the mean and (biased, ) variance over the examples in the batch, is a small constant that avoids division by zero, and are a learned scale and shift. At inference, and are replaced by running averages collected during training.
Steps
- Mean: .
- Variance: , so .
- Normalise: . Scale and shift: .
- Inference: keep running estimates during training, e.g. with a small rate (and the same for the variance), and use them at test time. The output then no longer depends on the other examples in the batch, and it is deterministic.
- Layer norm normalises each example over its own features, , instead of over the batch. Transformers use it because it works with batch size 1, variable sequence lengths and padding; it behaves the same in training and inference; and it avoids batch statistics, which are noisy for sequence data.
Common mistakes
- Using the variance when normalising during training (frameworks use there).
- Forgetting and , or saying they are fixed rather than learned.
- Using batch statistics at test time (forgetting model.eval()), which makes each prediction depend on the rest of the batch.
How long your answer should be
Half a page; the arithmetic takes 2 minutes and the explanation 2 more.
Last checked on 4 December 2026.
Read this
Previous in Deep learning: How does the product of layer Jacobians explain vanishing and exploding gradients in a deep feed-forward network, and why are sigmoid networks especially prone to vanishing gradients?
Next in Deep learning: How does the multiply-accumulate cost of a standard convolution compare with that of a depthwise separable convolution ( depthwise followed by pointwise), for an output with input and output channels? What is the ratio for and ?