3.1.12 · D2Neural Network Fundamentals

Visual walkthrough — Weight initialization (Xavier, He)

1,944 words9 min readBack to topic

Step 1 — What "spread" means (variance, from zero)

WHAT. Before touching neural nets, we need one measuring stick: how spread out is a bunch of random numbers? We call this the variance, written .

WHY this tool and not the average? The average (mean) tells you the center of a cloud of numbers — but a whisper and a scream can have the same center (zero). We care about loudness, i.e. how far numbers stray from the center. That is exactly what variance measures. See Variance and Expectation for the full toolkit; here is the one idea we need.

PICTURE. Two clouds of dots with the same center but different spread. The narrow cloud has small variance (quiet); the wide cloud has large variance (loud). The horizontal bars show one standard deviation — the typical distance from center.

Figure — Weight initialization (Xavier, He)
Recall Why zero-mean matters

Which is easier: average of , or average of ? ::: Average of — and they're equal exactly when , which is why we always center weights and inputs at zero.


Step 2 — One neuron is a sum of little pushes

WHAT. A single neuron computes one number before its activation:

  • = the -th input coming in,
  • = the weight (volume knob) on that input,
  • = fan-in, the number of inputs feeding this neuron (see Backpropagation for how these connect layer to layer).

WHY. Each product is one small "push" up or down. The neuron just adds them all. If all pushes are zero-mean and independent, they point randomly — some up, some down.

PICTURE. little arrows (the products ), pointing randomly up/down, being summed head-to-tail into one net arrow . Because they cancel partially, does not grow like — it grows like . That is the whole ballgame.

Figure — Weight initialization (Xavier, He)

Step 3 — How variance flows through the sum

WHAT. We compute the spread of . Two rules of variance (proven in Variance and Expectation) do all the work:

Put them together. All the share one spread , all share , so all terms are identical:

WHY this matters. This single equation is the amplifier gain of one layer. Read it as: output loudness = (fan-in) × (weight loudness) × (input loudness).

PICTURE. A funnel/amplifier: inputs each of variance enter; the box multiplies loudness by the factor ; out comes with variance . The multiplier is highlighted.

Figure — Weight initialization (Xavier, He)

Step 4 — Stack many layers: the gain gets a power

WHAT. Call the per-layer multiplier . If every layer has the same gain , then after layers the loudness is scaled by

  • = per-layer gain,
  • = depth (number of layers),
  • = total gain — a gain raised to the depth.

WHY this is the whole problem. An exponent is merciless:

  • , (loud scream),
  • , (dead silence),
  • , (perfect — the whisper stays a whisper).

This is Vanishing and Exploding Gradients in one line. The only safe target is .

PICTURE. Three curves of vs depth : orange rockets up (exploding), red collapses to zero (vanishing), green stays flat. Log scale on the y-axis to show the exponential.

Figure — Weight initialization (Xavier, He)

Step 5 — Solve for the weight spread (the forward answer)

WHAT. We demand and solve for the one thing we control — :

  • = fan-in (given by the architecture, fixed),
  • = the knob spread we get to choose.

WHY. More inputs (bigger ) means more pushes piling up, so each push must be quieter — hence weight spread shrinks like . This is the "variance-preserving forward" rule.

PICTURE. Two neurons side by side: a small one () with fat weight arrows, a big one () with thin weight arrows. A caption shows both produce the same output loudness because the thin knobs exactly cancel the extra inputs.

Figure — Weight initialization (Xavier, He)

Step 6 — The backward pass wants the other fan

WHAT. Training also sends gradients backward (see Backpropagation). The identical variance argument, run on the backward signal, replaces with (the number of outputs the neuron feeds):

  • = inputs into the layer (forward fan),
  • = outputs of the layer (backward fan).

WHY the conflict. Unless , you cannot satisfy both. Xavier/Glorot splits the difference by averaging the two demands: The "2" here is just the "" from averaging two $1/n$ targets — not the ReLU "2" of Step 8.

PICTURE. A tug-of-war rope: forward pass (blue) pulls toward , backward pass (orange) pulls toward . The green flag (Xavier) sits at the balance point .

Figure — Weight initialization (Xavier, He)
Recall The uniform version

Xavier is often written as . What is ? ::: , because a uniform on has variance ; setting gives the .


Step 7 — ReLU throws away half the signal

WHAT. So far we assumed the activation is (near-)linear, true for tanh/sigmoid near zero (see Activation Functions (ReLU, tanh, sigmoid)). But ReLU is : it deletes every negative value.

WHY it changes variance. If is symmetric around zero, exactly half its values are negative → set to . Killing half the values (the negative half) halves the average squared size:

  • = pre-activation (symmetric, zero-mean),
  • = post-ReLU output (only the positive half survives),
  • = the fraction of variance that gets through.

PICTURE. A symmetric bell of values; the left (negative) half is greyed-out/flattened to zero by ReLU; the surviving right half is shaded green. A bar on the right shows the output variance is exactly half the input variance.

Figure — Weight initialization (Xavier, He)

Step 8 — Compensate the halving: the He constant

WHAT. With ReLU, the real per-layer gain includes the : Demand again:

  • The = ReLU's damage from Step 7,
  • The in the answer = exactly what undoes that .

WHY. ReLU speaks only half the time, so we tell each input to speak twice as loud — that is the entire meaning of the "2" in He/Kaiming initialization. It is a different 2 from Xavier's averaging 2.

PICTURE. Side-by-side bar chart of the per-layer gain : with variance-preserving and ReLU, (signal decays — red); with He's and ReLU, (flat — green). A dashed line at marks the target.

Figure — Weight initialization (Xavier, He)

Step 9 — Every case, at a glance

Activation Damage factor Weight variance Name
linear / tanh / sigmoid (near 0) (fwd) or (both) Xavier
ReLU & variants He
all weights = 0 ❌ symmetry never breaks

Degenerate case — zero init. If , every neuron is identical: same output, same gradient, forever clones. Variance analysis assumes randomness; with zero spread there is nothing to preserve. That is why the recipe is random weights with a controlled variance, never a constant. This complements Batch Normalization, which re-fixes variance during training instead of just at the start, and underpins Deep Network Training Stability.


The one-picture summary

PICTURE. The full pipeline in one frame: inputs of variance → layer gain box → demand → branch into Xavier (, blue path, no halving) and He (, orange path, undoes ReLU's ½). Green output arrow of variance , unchanged through depth.

Figure — Weight initialization (Xavier, He)
Recall Feynman: the whole walkthrough in plain words

Variance is just loudness — how far random numbers stray from zero (Step 1). A neuron adds up many little pushes, and because they point randomly they don't all pile up (Step 2). The loudness of the sum equals how many pushes × knob loudness × input loudness (Step 3). Stack layers and this loudness factor gets raised to the depth, so anything but exactly explodes or dies (Step 4). Force the factor to and the knob loudness must be — quieter when there are more inputs (Step 5). The backward pass wants instead, so Xavier averages the two into (Step 6). ReLU deletes the negative half, halving the loudness (Step 7), so we speak twice as loud to compensate: , the He rule (Step 8). And setting everything to zero is banned because clones never learn (Step 9).


Connections