Here μ is the mean (the balance-point of the row), σ2 is the variance (average squared distance from that balance-point), x^i is the standardized value, and γi,βi are the learnable scale and shift. The tiny constant ϵ guards against dividing by zero.
The figure above is our mental model: a matrix whose rows are examples and columns are features. Look at the red row-arrow — that is the direction LayerNorm averages along. The blue column-arrow is what BatchNorm would use instead. Keep this picture handy for every question.
Across a row. LayerNorm takes one example (one row) and averages over all its H features. It never looks at other examples. (BatchNorm is the one that goes down a column — same feature, many examples.) See the red arrow in the figure above.
Recall Solution 1.2
x^i = the standardized activation (mean 0, variance 1 over the row). Not learnable — computed from the data.
γi = the learnable scale. Learnable.
βi = the learnable shift. Learnable.
So the network stretches (γ) and slides (β) the normalized values to whatever range suits the next layer.
Recall Solution 1.3
ϵ guards the division, which blows up when σ2→0 (a near-constant row). Placing it under the root, σ2+ϵ, guarantees the denominator is at least ϵ>0 even when σ2=0. If you added it after the root, σ2+ϵ, then when σ2 is exactly 0 the denominator is ϵ (fine) — but the standard convention puts it inside so the whole quantity stays a clean "variance plus floor." Either way the point is: never divide by zero.
Variance: squares (9,1,1,9), mean =420=5, so σ2=5, 5≈2.2360679...
Standardize:x^=(5−3,5−1,51,53)≈(−1.3416,−0.4472,0.4472,1.3416).
Check: sum =0 ✓ and mean of squares =5⋅49+1+1+9=2020=1 ✓.
Recall Solution 2.2
yi=3x^i−2:
y≈(3(−1.3416)−2,3(−0.4472)−2,3(0.4472)−2,3(1.3416)−2)=(−6.0249,−3.3416,−0.6584,2.0249).Mean of y: since each x^i averages to 0, mean(y)=3⋅0−2=−2=β. The affine step deliberately gives the row a new mean (β=−2) and a new standard deviation (γ=3).
Recall Solution 2.3
Mean:μ=7. Deviations: all 0. Variance:σ2=0.
Standardize: every numerator is 0, so x^i=0+10−50=0.
x^=(0,0,0,0).
Without ϵ this would be 00= NaN. With ϵ, a constant row cleanly maps to all zeros — no crash. This is exactly the degenerate case the parent's third mistake warned about.
New mean: μ′=H1∑(axi+b)=aμ+b. New deviation: xi′−μ′=(axi+b)−(aμ+b)=a(xi−μ). New variance: σ′2=H1∑a2(xi−μ)2=a2σ2, so σ′2=aσ2 (since a>0). Then
x^i′=aσ2a(xi−μ)=σ2xi−μ=x^i.
The a and b cancel exactly. Interpretation: if an earlier layer suddenly scales or offsets all its outputs, LayerNorm erases that change — the next layer sees identical inputs. This is the stability that fights Vanishing and exploding gradients.
Recall Solution 3.2
We need γix^i+βi=xi. Since xi=μ+σ2x^i (rearranging the standardize step), matching gives
γi=σ2=5≈2.2361,βi=μ=5.
Concretely with x^≈(−1.3416,…): 5⋅(−1.3416)+5≈2 ✓, recovering x1=2. So the affine step is expressive enough to make LayerNorm a no-op — proving γ,β are not redundant.
Recall Solution 3.3
BatchNorm's statistics for a feature are averaged down the column — over all examples in the batch. With batch size 1 the column has a single number, so its "variance" is 0 and the mean is just that number: standardizing gives 0, destroying all information (or NaN without ϵ). LayerNorm averages across the row of that single example's H features, which is always well-defined regardless of batch size. That is precisely why Transformers and RNNs adopt LayerNorm. See Internal covariate shift for the original motivation both methods share.
RMS:H1∑xj2=44+16+36+64=4120=30, so 30≈5.4772.
xˉ=(302,304,306,308)≈(0.3651,0.7303,1.0954,1.4606).Compare first entries: LayerNorm gave x^1≈−1.3416; RMSNorm gives xˉ1≈0.3651. They differ because RMSNorm skips centering (−μ), so it keeps the sign/offset of the raw value; LayerNorm re-centers first, flipping x1=2 (below the mean 5) to a negative standardized value. RMSNorm is cheaper (no mean) and often works comparably in Transformers.
Recall Solution 4.2
This is (2,4,6,8)×50 — a pure scaling of Ex. 2.1 by a=50. By the invariance proof (Ex. 3.1), LayerNorm erases the factor of 50:
z=x^≈(−1.3416,−0.4472,0.4472,1.3416),
identical to Ex. 2.1. Lesson: even if the residual branch F produces huge activations, the LayerNorm hands the next block bounded numbers — this is why LayerNorm placement tames Vanishing and exploding gradients in deep stacks.
Recall Solution 4.3
Since x^ has mean 0 and std 1, applying yi=γx^i+β gives mean β and std ∣γ∣. To hit mean 10, std 4:
β=10,γ=4.
Check on Ex. 2.1's x^: y1=4(−1.3416)+10≈4.6337, and the four outputs (4.6337,8.2111,11.7889,15.3663) have mean 10 and std 4. The affine step is just a linear map from the standard (mean 0,std 1) template to any (mean β,std γ) you like.
Write x^1=σ2x1−μ with μ=H1∑xj, σ2=H1∑(xj−μ)2. Both numerator and denominator are homogeneous of degree 1 in x: scaling x↦ax makes x1−μ↦a(x1−μ) and σ2↦aσ2. So x^1 is homogeneous of degree 0 — invariant. A degree-0 function's gradient is homogeneous of degree −1: ∂x1∂x^1ax=a1∂x1∂x^1x... but the derivative is taken with respect to the scaled coordinate, and by the chain rule that extra a cancels — the derivative of x^1 w.r.t. the input entry is scale-free. Explicitly, differentiating gives
∂x1∂x^1=σ21[(1−H1)−Hσ2(x1−μ)2].
For x=(2,4,6,8): σ2=5, x1−μ=−3, so
∂x1∂x^1=51[43−4⋅59]=51[0.75−0.45]=50.30≈0.1342.
For x=(20,40,60,80) (a=10): σ2=500, x1−μ=−30, giving 5001[0.75−4⋅500900]=5000.30⋅... wait — recompute: 2000900=0.45, so 5001(0.30)=22.3600.30≈0.01342. The raw derivative shrinks by a=10 — but the gradient the optimizer sees, ∂(scaled x1)∂x^1, is exactly 0.1342 again once you account for the coordinate scaling. Takeaway: LayerNorm makes the effective learning signal insensitive to the overall magnitude of a layer's activations — a key reason it stabilizes optimization.
Recall Solution 5.2
We know ∑jx^j2=H (from the parent's variance identity, since mean-square =1). For any single index i, x^i2≤∑jx^j2; the other H−1 terms are ≥0, but we can do better. The most extreme case puts all "mass" in one coordinate against the mean-zero constraint ∑jx^j=0. Maximizing x^i2 subject to ∑x^j=0 and ∑x^j2=H gives the other H−1 entries equal, and solving yields x^i2≤H−1, so ∣x^i∣≤H−1.
For H=4: bound is 3≈1.732. Our largest standardized value is x^4=53≈1.3416<1.732 ✓. So no standardized activation can explode — a built-in ceiling that helps prevent Vanishing and exploding gradients.
Train = inference (parent, mistake 4): LayerNorm needs no running averages, so the model behaves identically while training and while decoding — no train/test mismatch.
Scale stability around residuals (Ex. 4.2): deep Transformer stacks with residual branches can produce large activations; LayerNorm's scale-invariance (Ex. 3.1) hands each block bounded inputs, controlling Vanishing and exploding gradients. (Bonus: swapping to RMSNorm keeps points 1–3 while saving the mean computation.)
Recall One-screen recap
Axis: LayerNorm normalizes across the row (features of one example); BatchNorm down the column.
Recipe: subtract μ, divide by σ2+ϵ (divisor H, not H−1), then γx^+β.
Invariance: immune to shifting/scaling the whole vector (Ex. 3.1) — not to per-feature scaling (L3 trap).
γ,β can fully undo normalization ⇒ not redundant (Ex. 3.2).
Bounds:∣x^i∣≤H−1 (Ex. 5.2). Constant row → all zeros thanks to ϵ (Ex. 2.3).