LayerNorm⁡\operatorname{LayerNorm}

LayerNorm — layer normalization

Read "layer norm". It shifts and rescales each token's vector to have mean 0 and variance 1, then applies a learned scale and shift.

LayerNorm⁡(x)=x−μσ2+ϵ⊙γ+β\operatorname{LayerNorm}(\mathbf{x}) = \frac{\mathbf{x} - \mu}{\sqrt{\sigma^2 + \epsilon}} \odot \boldsymbol{\gamma} + \boldsymbol{\beta}. Here μ\mu and σ2\sigma^2 are the mean and variance of the numbers within one token's vector. So the result for one token does not depend on the other examples in the batch, unlike BatchNorm. γ\boldsymbol{\gamma} (gain) and β\boldsymbol{\beta} (bias) are learned per feature.

It keeps activations in a steady range as layers stack up. Whether it is placed before the sub-layer (Pre-LN) or after the residual addition (Post-LN) affects whether deep models need a learning-rate warmup to train.

Example

[1,2,6]  →  [−2,−1,3]14/3≈[−0.93, −0.46, 1.39][1, 2, 6] \;\to\; \frac{[-2, -1, 3]}{\sqrt{14/3}} \approx [-0.93,\, -0.46,\, 1.39]

Mean 3, variance 14/3 (ignoring ε, with γ = 1 and β = 0).

Where the course uses it

Related terms