ResNet uses BN after every conv
Inserted between conv and ReLU. Without it, ResNet-50 doesn't train well.
nn.Sequential(nn.Conv2d(...), nn.BatchNorm2d(64), nn.ReLU())Name things for the reader, not the writer.
Name things for the reader, not the writer.
Deep Learning Building Blocks
Batch normalization (Ioffe & Szegedy 2015) normalizes each feature across a mini-batch: hat{x}_{ic} = (x_{ic} - mu_c)/sqrt{sigma_c^2 + epsilon}, then scales and shifts with learnable gamma_c, beta_c. At test time it uses running averages of mu, sigma^2 accumulated during training.
BatchNorm normalizes across the batch; LayerNorm across features within an example.
Batch normalization (Ioffe & Szegedy 2015) normalizes each feature across a mini-batch: , then scales and shifts with learnable . At test time it uses running averages of accumulated during training.
BatchNorm dramatically accelerates training of deep nets, allows higher learning rates, and acts as a mild regularizer. The original motivation (reducing 'internal covariate shift') was later questioned — the modern understanding is that BN smooths the loss landscape (Santurkar et al. 2018).
Layer normalization normalizes across features within a single example rather than across the batch. This makes it batch-size-invariant and works on sequences of varying length, which is why it became the default in transformers.
Python (in browser)
Expected: BN zeroes column means; LN zeroes row means.
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Other variants: Group normalization groups channels and normalizes per group; instance normalization normalizes each example × channel independently (popular in style transfer); RMSNorm drops the mean centering (used in LLaMA).
Inserted between conv and ReLU. Without it, ResNet-50 doesn't train well.
nn.Sequential(nn.Conv2d(...), nn.BatchNorm2d(64), nn.ReLU())Pre-LN (modern) places LayerNorm before attention/MLP. Stabilizes training of 100+ layer transformers.
Drops the mean-subtraction step; only divides by RMS. Slightly faster, comparable quality.
Put your understanding to the test. Score + streak + speed all count.
3 quick questions. Get 2 right to mark this lesson complete.