AI Grounds

Open AI Grounds on a desktop

These interactive lessons need a larger screen. Please continue on a desktop or laptop computer.

Guided discovery

Layer Normalization Lab

Change a feature. Follow its row. Keep the axes straight.

Your dataset · three tokens, four features

Each row represents one token—a position in this toy sequence. Its features are illustrative numeric signals, not generated word embeddings. LayerNorm here uses all four features in the selected row.

Raw inputs. The selected token row is highlighted; edit one feature below.
TokenFeature 1Feature 2Feature 3Feature 4
The0.20-0.800.400.10
cat · selected-1.00-1.001.001.00
sat0.300.50-0.70-0.10

Edit cat, feature 1, only. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

Gamma multiplies this feature’s z in all tokens. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

Beta adds to this feature’s output in all tokens. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

Make row constant sets the selected row’s four inputs to zero. Scale and Shift are per-feature parameters shared across all three tokens; you edit them manually here.

Follow cat’s four features

Input xMean 0.000000 · std 1.000000
Normalized zMean 0.000000 · std 0.999995
Output yMean 0.075000 · std 1.134400

Fixed numeric axes −5 to 5 keep spread changes visible. Each numbered lane follows one feature; the outlined dot marks your selection. x and y are numeric activations; z is dimensionless. Exact values are below.

cat · feature 1

z = (-1.000000 − (0.000000)) / √(1.000000 + 0.00001) = -0.999995

y = 1.20 × (-0.999995) + (0.10) = -1.099994

Substitutions are rounded; calculations use full precision. Epsilon (0.00001) is a positive term protecting the denominator. z’s sign follows x−mean; Scale and Shift act afterward.

Row mean

Average of this token’s four raw features.

0.0000

mean = Σx / 4

Normalized mean 0.000000; output mean 0.075000.

Row variance

Average squared distance from the raw row mean.

1.0000

variance = Σ(x−mean)² / 4

Raw std √variance = 1.000000. Denominator √(variance+epsilon) = 1.000005.

Output spread

Population standard deviation around y’s actual mean.

1.1344

yᵢ = Scaleᵢ × zᵢ + Shiftᵢ

var(z) = variance/(variance+epsilon) = 0.999990. Per-feature parameters need not preserve zero mean or unit spread.

Exact feature values
cat: computed values rounded to six decimals.
FeatureInput xNormalized zOutput y
1 · selected-1.000000-0.999995-1.099994
2-1.000000-0.999995-0.999996
31.0000000.9999950.999995
41.0000000.9999951.399995
Compare with a BatchNorm column

Declare the layout first. LayerNorm input [1, 3, 4] has one sequence, three token positions, four features; normalized_shape=4 uses four features per token. For BatchNorm1d, transpose the same data to [N=1, C=4, L=3]: one sequence, four feature channels, three positions. Its training forward calculation uses each channel across those three positions, as this column shows. The positions are not three independent batch examples.

BatchNorm comparison: highlighted feature 1 column. The main plots still show LayerNorm.
TokenF1F2F3F4Column z
The0.20-0.800.400.100.620757
cat-1.00-1.001.001.00-1.410811
sat0.300.50-0.70-0.100.790054

Selected column mean -0.166667, population variance 0.348889; z=(x−column mean)/√(column variance+0.00001). This comparison omits affine parameters to isolate axes. LayerNorm selected row mean 0.000000, variance 1.000000.

What this model includes

Population variance divides by the number of contributing values. LayerNorm normalizes the declared trailing dimensions; this demo uses four features. It computes statistics from the current input in both training and evaluation. Per-feature gamma and beta are shared across leading token/sequence dimensions. The lab permits positive scales 0.4–1.8; real parameters can also be zero or negative.

The three words label illustrative rows; features have no assigned linguistic meaning. No optimizer, running-statistic update or training-quality comparison runs. The BatchNorm example describes the training forward grouping with explicit N,C,L axes; evaluation behavior can use saved running statistics.

PyTorch LayerNorm reference · BatchNorm1d reference.

cat, feature 1. Row mean 0.000000, variance 1.000000, denominator 1.000005. Selected x -1.000000, z -0.999995, y -1.099994. Scale 1.20, Shift 0.10 are shared with this feature in other tokens.