Initialization and activation scale
Explain why weights are initialized with variance ∝ 1/fan_in (fan_in = number of inputs to each unit), so activations neither blow up nor shrink layer by layer. Predict what happens with a bad initialization scale.
Builds on: Variance of sums and dot products of random vectors, MLPs and why nonlinearities matter
What the animation says
The narrow window
Before training, every weight in a network is a random number. How big should those numbers be? Take twenty linear layers, each one thousand twenty-four wide, and feed in values of size about one. With weights of standard deviation one, the output comes out about ten to the thirty times bigger. With standard deviation one hundredth, it comes out ten to the minus ten times smaller. So the safe window is narrow. Start with a single layer: by what factor does it multiply the scale?
One layer, then depth
Thirty-two. Each output adds up one thousand twenty-four products: an input times a weight. Independent terms add their variances, so the output variance is n, times the weight variance, times the input's. The size, the standard deviation, grows by the square root of n times the weight's std: thirty-two per layer. Depth compounds it. Ten layers: thirty-two to the tenth, about ten to the fifteen. Weights of one hundredth give point three two per layer, about ten to the minus five. Which weight scale makes the per-layer factor exactly one? Tap it.
ReLU halves it
So for a plain linear layer, use weight variance one over n. Now put a ReLU after it. Each output is a sum of many independent terms with mean zero, so it's roughly symmetric around zero. ReLU zeroes the negative half and keeps the positive half. The mean square drops by half, so the size shrinks by root two per layer. To compensate, double the weight variance: two over n. That's He initialization. Width five hundred twelve, ten ReLU layers, weights one over root n. How big is the output?
Run it
About point oh three. Let's check in code: a batch of random inputs, width five hundred twelve, ten layers. This loop tries three weight scales. Each layer draws fresh random weights, multiplies, then applies ReLU. One over root n: the size shrinks to about point oh three, just as predicted. Root of two over n, the He scale: it stays near one. Point one: the size grows about one point six times per layer, ending near a hundred.
Keep the factor at 1
Why does this matter? Too large, and values blow up toward infinity and not-a-number. Too small, and the signal fades. Biases and rounding swamp it, or it underflows to zero. Then the output carries almost no information about the input, and learning struggles to start. The rule: keep each layer's factor at one. Weight variance one over fan-in, or two over fan-in when a ReLU follows.
Each layer multiplies the scale; depth compounds
Variance through one layer
Width 1024, three weight scales
Watch a 20-layer ReLU stack
import numpy as np
rng = np.random.default_rng(0)
n, L = 512, 20
x = rng.standard_normal((1000, n))
for s in [1/np.sqrt(n), np.sqrt(2/n), 0.1]:
h = x
for _ in range(L):
h = np.maximum(0, h @ (rng.standard_normal((n, n)) * s))
print(f"{s:.4f} rms={np.sqrt((h**2).mean()):.3g}")
Keep the per-layer factor at 1
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.
Bytewise
All courses