Equations · Ioffe and Szegedy, “Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift” (2015)
The batch normalization (BatchNorm) formula, explained
BatchNorm normalizes each feature using the mean and variance of that feature across the mini-batch, then applies a learned scale and shift. It is computed per feature (per channel in a CNN), across examples. LayerNorm does the opposite: per example, across features.
Term by term
The mini-batch: the values of one feature, one per example. The calligraphic is a name for the set, used here as a subscript label.
Calligraphic letters · Subscript (index or label) · Dots (ellipsis)
The batch variance (dividing by , not ). is a standard deviation here, not the sigmoid.
The normalized value: mean 0, variance 1 across the batch. (about ) avoids division by zero.
"Is by definition": the whole transform is named , with its parameters written as subscripts.
Shapes
- For a dense layer, input : the statistics are taken over the rows, giving means and variances.
- For a CNN, input : one mean and variance per channel, taken over , and . .
A small worked example
One feature over a batch of four: . , , so . With , : . At inference there is no batch, so running averages of and collected during training are used instead.
In code
import numpy as np
def batch_norm(x, gamma, beta, eps=1e-5):
# x: (B, d); statistics over the batch axis
mu = x.mean(axis=0)
var = x.var(axis=0)
return gamma * (x - mu) / np.sqrt(var + eps) + betaEvery symbol in it
Other equations
- Scaled dot-product attention
- Softmax
- Cross-entropy loss
- Adam update
- Layer normalization
- RMSNorm
- The ELBO
- KL divergence
- Backpropagation through one layer
- LoRA
- GELU
- Dropout
- Rotary position embedding (RoPE)
- Multi-head attention
- PPO clipped objective
- DPO loss
- Policy gradient (REINFORCE)
- Bellman equation
- Q-learning update
- InfoNCE contrastive loss
- Diffusion forward process
- DDPM simplified loss
- VAE reparameterization trick
- GAN minimax objective
- AdamW
- Cosine learning-rate schedule
- Perplexity
- Logistic regression
- Normal equation (linear regression)
- Singular value decomposition (SVD)
- Principal component analysis (PCA)