3.4 Initialization and normalization
1. Learn
Section titled “1. Learn”- Understanding Deep Learning (Prince)§7.5 Parameter initialization (pp. 107–111) and §11.4 Batch normalization (pp. 192–195)
- Karpathy, Building makemore Part 3: Activations & Gradients, BatchNorm00:04:19–01:03:07 (fixing the initial loss and the saturated tanh, Kaiming init, batch normalization) and 01:26:51–01:51:34 (the four activation and gradient visualizations); video length 1:55:57
2. Bridge
Section titled “2. Bridge”Variance through depth. A unit sums inputs times weights, so with independent weights of variance its pre-activation has variance about times that of the inputs. A ReLU then zeroes half of it. Unless , the scale shrinks or grows by the same factor at every layer: geometrically, so after 50 layers it is either zero or overflow, and the gradients flowing back do the same (UDL §7.5).
He initialization sets for ReLU layers (He et al. 2015). Xavier initialization uses about for tanh, which is roughly linear near zero (Glorot and Bengio 2010). Set the depth to 40 in the lab and switch between them.
BatchNorm stops relying on the initialization. For each feature it subtracts the batch mean and divides by the batch standard deviation, then applies a learned scale and shift so the layer can still represent any mean and variance (Ioffe and Szegedy 2015; UDL §11.4). The catch is that an example’s output depends on the rest of its batch. At evaluation time there may be no batch, so BatchNorm keeps running averages of the statistics during training and uses those instead. Forgetting to switch modes is a classic bug.
LayerNorm normalises each example over its own features instead (Ba et al. 2016). It needs no batch statistics, so training and evaluation behave the same and it works for sequences of any length. That is why transformers use it, or its cheaper cousin RMSNorm, which skips the mean (Zhang and Sennrich 2019).
The backward pass is the interesting part: the mean and variance depend on every example in the batch, so each input’s gradient picks up two extra terms (Ioffe and Szegedy 2015, §3).
3. Explore
Section titled “3. Explore”Implement He initialization, then BatchNorm and LayerNorm with their backward passes. The tests check the normalised statistics, run both backward passes through a gradient checker, and make sure evaluation mode uses the running statistics.
stubs/m3_4_norms.pyLoading starter file…
Prefer your own editor? Edit exercises/stubs/m3_4_norms.py and run mlc check 3.4. The tests are identical; import the results on the progress page.
Locally: mlc check 3.4.
5. Check
Section titled “5. Check”- not yet: All tests pass (0/?)
- not yet: Checkpoint quiz ≥ 80%
Learner log: time spent and points of confusion
Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.