3.1.12 · D3Neural Network Fundamentals

Worked examples — Weight initialization (Xavier, He)

2,696 words12 min readBack to topic

Before anything, two reminders of the vocabulary (built in the parent, repeated so you never guess):


How to read the scenario matrix

Every weight-init question is one of the nine cells below. First skim the flowchart — it is the "decision tree" you walk to land on the right cell; then the table names each cell and its example.

ReLU family

tanh sigmoid linear

no

yes

n_in is 1

normal

uniform

too big

too small

mixed per layer

A layer to initialize

activation?

use He 2 over n_in

use Xavier 2 over sum of fans

n_in equals n_out?

sampling?

cell A Ex1

cell C Ex3

cell E Ex5

cell B Ex2

cell D Ex4

constant correct?

cell F Ex6 explode

cell G Ex7 vanish

cells H I Ex8 Ex9

Cell Situation What makes it tricky Example
A ReLU layer, He uses only fan-in → output size is a decoy Ex 1
B tanh/sigmoid layer, general Xavier uses both fans Ex 2
C Square layer He vs Xavier give different answers even here Ex 3
D Uniform sampling (need bound ) must convert variance → half-width via Ex 4
E Degenerate: limiting/edge case, formula still holds Ex 5
F Wrong constant → exploding per-layer gain , raised to depth Ex 6
G Wrong constant → vanishing per-layer gain , raised to depth Ex 7
H Real-world word problem pick activation → pick init → size it Ex 8
I Exam twist: mixed activations which formula per layer, and why Ex 9

Example 1 — ReLU layer, fan-in ≠ fan-out (cell A)


Example 2 — tanh layer, general fan-in ≠ fan-out (cell B)


Example 3 — Square layer: He and Xavier disagree (cell C)


Example 4 — Uniform sampling: convert variance to a bound (cell D)


Example 5 — Degenerate case: a single input, (cell E)


Example 6 — Wrong constant → explosion (cell F)

Figure — Weight initialization (Xavier, He)

Example 7 — Wrong constant → vanishing (cell G)

Figure — Weight initialization (Xavier, He)

Example 8 — Real-world word problem (cell H)


Example 9 — Exam twist: sigmoid then ReLU, same shape (cell I)


Recall Quick self-test

ReLU : which fan and which constant? ::: He, ; fan-out is ignored. tanh variance? ::: Xavier . Xavier uniform half-width for ? ::: (from ). He variance for ? ::: (still preserves variance after ReLU). Naive on ReLU, 6 layers — total gain? ::: (explodes). Why is a square layer's He twice its Xavier? ::: Xavier denominator is , so it is half of He's — ReLU's compensation factor. What value do we initialize biases to, and why? ::: Zero — biases have no fan-in to amplify and keeping preserves the zero-mean assumption the variance derivation needs.


Connections