A transformer layer-norm sees the feature vector x=(1,3,5,7) for one token, with γ=2, β=1 for every feature and ϵ=0. 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

LN(x)i=γ xi−μσ2+ϵ+β, where μ and σ2 are the mean and variance over the features of this one token.

Steps

  1. Mean μ=(1+3+5+7)/4=4.
  2. Variance σ2=14(9+1+1+9)=5, so σ=5=2.236.
  3. Normalised values: (−3,−1,1,3)/2.236=(−1.342, −0.447, 0.447, 1.342).
  4. Scale and shift: 2× value +1=(−1.683, 0.106, 1.894, 3.683).
  5. 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.
  6. That is why layer norm suits variable-length sequences and small batches, and why it behaves the same in training and inference.

Common mistakes

How long your answer should be

Half a page; 2–3 minutes.

Last checked on 4 December 2026.

Read this

Previous in Sequence models and transformers: Take the sinusoidal positional encoding with dmodel=4, ordered as (sin⁡,cos⁡) pairs, PE(pos,2i)=sin⁡ ⁣(pos/100002i/d) and PE(pos,2i+1)=cos⁡ ⁣(pos/100002i/d). What is the vector for position pos=2?
Next in Sequence models and transformers: An encoder gives hidden states h1=(1,0), h2=(0,1) and h3=(1,1). The decoder state is s=(2,1). Using Luong dot-product attention, compute the attention weights and the context vector. How does Bahdanau (additive) attention differ?