Zero does not work, and neither does large
If every weight starts identical, every unit in a layer receives the same gradient and stays identical forever. The layer has one unit's worth of capacity, whatever its width.
Randomness is what breaks that symmetry, which is why initialisation is random rather than clever.
The scale is the harder half. A layer's pre-activation is a sum of products, so its variance grows with the fan-in unless the weights shrink to match.
Keeping the variance at one
Setting the weight variance to the reciprocal of the fan-in makes the output variance equal to the input variance, so a signal neither explodes nor dies as it passes through the stack.
Xavier initialisation averages the two directions, because the forward pass is scaled by the fan-in and the backward pass by the fan-out.
It assumes the activation is roughly linear near zero, which is true of tanh and false of ReLU.
He initialisation corrects for that. ReLU zeroes half its inputs and so halves the variance, and the factor of 2 puts it back.
Use He with ReLU and its relatives, Xavier with tanh and sigmoid. Getting this one factor wrong is enough to stop a 30-layer network training at all.
One initialisation, in order
- Read the layer's fan-in, and its fan-out if using Xavier.
- Pick the variance from the rule that matches the activation.
- Draw the weights from a normal or uniform distribution with that variance.
- Set every bias to zero, since the weights have already broken the symmetry.
- Check the activation statistics on one forward pass before training anything.
What to look at when it goes wrong
Push one batch through an untrained network and print the standard deviation of each layer's activations.
Falling steadily towards zero means the initialisation is too small and the signal is dying. Growing without bound means it is too large.
A healthy start is roughly flat across depth, and it costs one forward pass to check.
Why it matters less than it used to
Normalisation layers rescale activations at every step, so a network with batch norm or layer norm tolerates an initialisation that would otherwise be fatal.
Residual networks go further and scale the residual branches down by the depth, so the identity path dominates at the start and the network begins close to shallow.
Initialisation is now insurance rather than the main event, and it is still the first thing to check when the loss does not move at all.