A transformer layer-norm sees the feature vector for one token, with , for every feature and . What is the output? How does the statistics axis of layer norm differ from batch norm?
Sequence models and transformers, Normalisation
Level L2 Elementary. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can compute layer norm over the feature axis of one token, and know why transformers use it instead of batch norm.
Key idea
, where and are the mean and variance over the features of this one token.
Steps
- Mean .
- Variance , so .
- Normalised values: .
- Scale and shift: value .
- Batch norm takes mean and variance over the batch (for each feature). Layer norm uses only the features of one token, so it does not depend on other examples or batch size.
- That is why layer norm suits variable-length sequences and small batches, and why it behaves the same in training and inference.
Common mistakes
- Dividing by the variance instead of the standard deviation.
- Using the sample variance when the definition uses .
- Computing the mean across tokens instead of across features.
How long your answer should be
Half a page; 2–3 minutes.
Last checked on 4 December 2026.
Read this
- Ba, Kiros and Hinton (2016), Layer normalization: Section 3 defines the mean and variance over the features of one example, in contrast with batch normalisation.
- Dive into Deep Learning, batch normalization: The layer normalization section gives the formula, and the text contrasts the statistics axis with batch norm.
- NPTEL: Deep Learning (IIT Kharagpur, Prof. Prabir Kumar Biswas): Week 10, Lecture: Layer, Instance, Group Normalization, which covers computing layer-normalisation statistics per example.
Previous in Sequence models and transformers: Take the sinusoidal positional encoding with , ordered as pairs, and . What is the vector for position ?
Next in Sequence models and transformers: An encoder gives hidden states , and . The decoder state is . Using Luong dot-product attention, compute the attention weights and the context vector. How does Bahdanau (additive) attention differ?