3.2.9 · D1Training Deep Networks

Foundations — Layer normalization

1,940 words9 min readBack to topic

Before you can read the parent note, you must own every symbol it throws at you. We build them one at a time, each anchored to a picture, each earned before the next uses it. Nothing here assumes you have seen the notation before.


1. A vector — the list of numbers

The parent writes . Let us un-pack every piece.

The picture. Think of a row of bars, one bar per number, its height equal to that number. That row is the vector.

Why the topic needs it. A neuron does not emit a single number — it emits a whole row of them, one per "unit". LayerNorm works on that entire row at once, so we need a name for the row (that is ) and a name for each individual bar (that is ).


2. — how long the list is

The picture. Count the bars in the previous figure. That count is .

Why the topic needs it. LayerNorm averages across the features. To average, you must divide by how many things you added up — that count is . Every formula that begins is saying "add these up and divide by how many there are", i.e. take an average.


3. — the adding-up machine

The formulas use . This scares people; it should not.

The picture. Imagine sliding a bucket from the first bar to the last, tipping each bar's height into the bucket. The final level in the bucket is the sum.

Why the topic needs it. Every statistic in LayerNorm — the mean, the variance — is "add something over all features". The is that adding.


4. — the mean (the balance point)

Now we can read the first real formula: .

The picture. Put the bars on a see-saw. The mean is the point where the see-saw balances. Numbers above the mean pull right; numbers below pull left; at the pulls cancel.

Why the topic needs it. LayerNorm's first job is to recentre the row so its balance point sits at zero. To move it to zero you must first know where it currently balances — that is .


5. Deviation — distance from the balance point

The picture. Draw a horizontal line at height . Each deviation is the signed gap from that line up (or down) to the top of a bar.

Why the topic needs it. "Centring to zero" is replacing each with its deviation. A remarkable fact used later: the deviations always add to zero, because the amounts above the balance point exactly match the amounts below.


6. — the variance (how spread out)

Next: .

The picture. A narrow cluster of bars near the mean → small . A wide fan of bars → large .

Why the topic needs it. After centring, LayerNorm rescales the row so its spread becomes exactly 1. To shrink or stretch the spread to 1, you must first measure it — that is .


7. , the hat, and — the standardized value

Now the payoff line: .

Why the topic needs it. This one formula is the heart of LayerNorm. Everything before it (vector, , , , deviation, ) existed only so this line could be read and believed.


8. , — the two learnable knobs

Final line: .

Recall Read every symbol aloud

::: the whole row of numbers for one example ::: the -th single number in that row ::: how many numbers are in the row (the count of features) ::: add up over all features ::: the mean — the balance point of the row ::: deviation — signed distance from the balance point ::: variance — average of the squared deviations ::: standard deviation — a typical distance from the mean ::: the standardized value (mean 0, variance 1) ::: tiny number that prevents dividing by zero ::: learnable scale and shift applied after standardizing


How these feed the topic

Vector x and entry x_i

Feature count H

Summation sum

Mean mu

Deviation x_i minus mu

Variance sigma squared

Std deviation sigma

Standardize x_i hat

Epsilon safety

Scale gamma and shift beta

Layer normalization

Read top-to-bottom: the vector and its length give us the mean; the mean gives deviations; deviations give variance and spread; spread plus let us standardize; and the two knobs finish the job. Only once all of these are in hand does the parent topic Layer normalization make sense.


Where these ideas reappear

  • The same mean/variance machinery, but averaged down a column instead of across a row, is Batch normalization — its column-vs-row difference is the whole story.
  • Normalizing to keep activations tidy is a direct defence against Vanishing and exploding gradients.
  • The instability LayerNorm fights — shifting input distributions — is Internal covariate shift.
  • LayerNorm is the normalizer of choice inside Transformers, works alongside Residual connections, and has a leaner cousin RMSNorm that drops the mean-subtraction step.
  • The "tidy range" matters because the next stage is usually an activation function — see Activation functions.
  • Prefer Hindi? Yeh Hinglish mein padho →

Equipment checklist

Self-test: can you answer each without peeking?

Read in the vector .
— the third entry.
What does equal for ?
— there are four features.
Expand in plain addition.
.
Compute the mean of .
.
What is the deviation of from that mean?
(below the mean, so negative).
Why do we square deviations before averaging them?
Raw deviations always cancel to 0; squaring keeps them positive so spread is measured.
What does (no square) represent?
The standard deviation — a typical distance from the mean, in original units.
In , what does the numerator do and what does the denominator do?
Numerator centres to 0; denominator rescales spread to 1.
Why is in the denominator?
To avoid dividing by (near) zero when the row is nearly constant.
What do and let the network do?
Re-scale and re-shift the tidy values — even fully undo normalization if that helps.