Comparing batch normalization with layer normalization

← Back to Blog & Articles

Deep networks suffer from internal covariate shift: as earlier layers' weights update, the distribution of inputs to later layers keeps changing, forcing those layers to continually re-adapt.

Deep networks suffer from internal covariate shift: as earlier layers' weights update, the distribution of inputs to later layers keeps changing, forcing those layers to continually re-adapt. Batch normalization normalizes each layer's pre-activation across the batch dimension:

ẑ = (z - μ_batch) / √(σ²_batch + ε), output = γẑ + β

where μ_batch, σ²_batch are computed per-feature across the current mini-batch, and γ, β are learned parameters that let the network recover the original (unnormalized) representation if that turns out to be optimal — the normalization does not remove expressive power, since γ=√(σ²_batch+ε), β=μ_batch exactly inverts it. Batch normalization requires a reasonably large batch size for its batch statistics to be meaningful, and behaves differently at train time (batch statistics) versus test time (a running average of batch statistics accumulated during training), which is a common source of bugs when a model is put into evaluation mode incorrectly.

Layer normalization normalizes across the feature dimension for each individual example instead of across the batch, making it independent of batch size and identical at train and test time — this is why Transformers (the companion book), which are often trained and served with variable or very small batch/sequence configurations, use layer normalization rather than batch normalization.

Continue with the book

Explore the full treatment, worked examples, and exercises in The AI Algorithms Compendium.


Companion article for The AI Algorithms Compendium, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.

Scroll to Top