2.10 — Weight initialisation: Xavier/Glorot and He
Goal: Derive variance-preserving initialisations: Xavier (linear/tanh, 1/n) and He (ReLU, 2/n).
1. Why this session exists
Section 2.9 left an open question: even if the activation has well-behaved , the matrix factors in the backprop chain can themselves rescale the gradient. To keep activations and gradients well-scaled across depth, we initialise weights with a carefully chosen variance. The two recipes are Xavier/Glorot (linear or tanh) and He (ReLU).
This is one of those moments where deep learning's empirical fix turns out to come from a one-line calculation.
2. Setup: variance propagation through a linear layer
Consider one linear layer
with , , (for now). Assume entries of are i.i.d. with mean and variance , independent of . Then
Compute . With and independence,
(With centred and i.i.d. across , .)
To preserve variance through the layer, , we need
This is the variance-preservation principle for forward propagation.
3. Xavier / Glorot initialisation (Glorot & Bengio, 2010)[1]
Glorot's full analysis does the same calculation in the backward pass and asks for both forward and backward variances to be preserved. Backward through the linear layer (from 2.6),
To preserve we need . Forward wants ; backward wants . Compromise: take the harmonic mean,
In practice we sample or, equivalently variance-wise, with .
This was the right choice when the dominant activation was tanh, which has — so the activation doesn't change the variance budget. With sigmoid hidden layers, Xavier was already a marked improvement on the previous "random scale, hope" approach.
4. He initialisation (He et al., 2015)[2]
For ReLU activations the calculation needs one more step. Recall (2.3, 2.9) that and that for a symmetrically distributed , half the time. Plugging this into the variance propagation:
assuming a centred symmetric . So passing through a ReLU halves the variance. To compensate, the next layer's weight matrix should double the variance budget:
This is the He (or Kaiming) initialisation — the default for ReLU networks today (nn.init.kaiming_normal_ in PyTorch).
Why this matters concretely. Without the correction, ReLU networks see their activation variance halve at every layer; after layers, the typical activation magnitude has shrunk by , and the network is effectively dead. He init keeps the activation variance constant across depth.
5. Generalisations
Two natural extensions.
Generic activation with derivative-magnitude at the initialisation scale. The compensating variance is
Plugging (ReLU half-on) gives , recovering He. Plugging (tanh near zero) gives , recovering Xavier-forward.
Layer-wise scale rescue. Modern alternatives like LSUV (Mishkin & Matas, 2016) iteratively rescale each layer's weights so that the actual variance of at initialisation matches a target value, measured on a real batch. More accurate than the closed-form rule, more annoying to implement.
6. Biases
Biases are usually initialised to zero. There is no variance to preserve — biases shift means, not variances. Exception: the bias of the output logit for a binary classifier on imbalanced data is sometimes initialised to so that the network's prior prediction at step 0 matches the class frequency.
7. A common pitfall
Many older codebases (and CV pipelines from the early 2010s) use the forward-only Xavier variance across the board — tanh or ReLU, indifferently. For tanh-activated networks this is fine. For ReLU networks it under-scales the weights by a factor of in variance, and the activation variance halves at every layer (§4). The fix is one line: switch the scaling factor from to (or call nn.init.kaiming_normal_ in PyTorch) and trainability improves immediately. A small but real example of how the theory keeps catching up to the practice.
8. Takeaways
- Forward-variance preservation: .
- Backward-variance preservation: .
- Xavier (compromise): . Use with linear or tanh.
- He (ReLU correction): . Use with ReLU.
- Biases initialise to zero unless you have prior class-imbalance information.
(a) Verify the §2 variance computation step by step, being explicit about which independence and centring assumptions you used.
(b) Derive the ReLU compensation factor of in §4 by computing for .
(c) For a 10-layer ReLU MLP with widths all equal to , compute the expected magnitude of relative to under (i) Xavier init, (ii) He init.
(d) Why don't we just initialise all weights to ? (Hint: think about what happens to the symmetry between units in the same layer when every weight is identical and the gradient is also identical.)
References
- [1]
Glorot, X., & Bengio, Y. (2010). "Understanding the difficulty of training deep feedforward neural networks". AISTATS. — Xavier/Glorot initialisation (2.10).
↩ - [2]
He, K., Zhang, X., Ren, S., & Sun, J. (2015). "Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification". ICCV. arXiv:1502.01852 — He / Kaiming initialisation (2.10).
↩