What is the batch normalisation forward pass for one feature? For a mini-batch of activations [1,2,3,6] with γ=2, β=1 and ϵ≈0, 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

x^i=xi−μBσB2+ϵ and yi=γx^i+β. Here μB and σB2 are the mean and (biased, 1/m) variance over the m examples in the batch, ϵ is a small constant that avoids division by zero, and γ,β are a learned scale and shift. At inference, μB and σB2 are replaced by running averages collected during training.

Steps

  1. Mean: μB=(1+2+3+6)/4=3.
  2. Variance: σB2=((−2)2+(−1)2+02+32)/4=14/4=3.5, so σB≈1.871.
  3. Normalise: x^≈[−1.069, −0.535, 0, 1.604]. Scale and shift: y=2x^+1≈[−1.138, −0.069, 1, 4.207].
  4. Inference: keep running estimates during training, e.g. μrun←(1−α)μrun+αμB 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.
  5. Layer norm normalises each example over its own d features, μ=1d∑j=1dxj, 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

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 k×k convolution compare with that of a depthwise separable convolution (k×k depthwise followed by 1×1 pointwise), for an H×W output with Cin input and Cout output channels? What is the ratio for k=3 and Cout=256?