← All Posts
Deep Learning · Weight Initialization in Deep LearningChapter 01 / 2

Initialization: Break Symmetry and Keep Signals Alive

See why identical hidden units stay identical, derive the per-layer signal multiplier, and track how weight scale compounds across depth.

Weight initialization has two jobs before the first gradient step: ensure hidden units learn distinct features, and keep forward activations and backward gradients from vanishing or exploding as they pass through many layers.

1. Why identical hidden units stay identical

If hidden neurons in a layer start with identical parameters, they compute the same forward activation and receive the same backward gradient on every step. Compare three ways of initializing a layer’s weights $W$ and biases $b$:

2. How one layer changes signal scale

Single neuron preactivation diagram showing n_in inputs a_1, a_2, ..., a_{n_in} multiplied by weights W_1, W_2, ..., W_{n_in} and summed to form z = sum_{j=1}^{n_in} W_j a_j with second moment E[z^2] = n_in s_W^2 q.
Scroll the figure horizontally on small screens.
A single hidden unit summing $n_{\rm in}$ weighted inputs $z=\sum_{j=1}^{n_{\rm in}}W_ja_j$, where each incoming path has input second moment $\mathbb E[a_j^2]=q$ and weight variance $\operatorname{Var}(W_j)=s_W^2$.

Breaking symmetry only requires random weights, but picking an arbitrary scale like $W_{ij}\sim\mathcal N(0,0.01^2)$ fails in deep networks. Consider a single preactivation $z=\sum_{j=1}^{n_{\rm in}}W_ja_j$, where weights $W_j$ are independent with mean $\mathbb E[W_j]=0$ and variance $\operatorname{Var}(W_j)=\mathbb E[W_j^2]=s_W^2$, and are independent of the inputs $a_j$, which have second moment $q=\mathbb E[a_j^2]$.

First, compute the expected value (mean) $\mathbb E[z]$. By linearity of expectation and the independence of $W_j$ and $a_j$, the mean of $z$ is always zero—even if the inputs $a_j$ have a nonzero mean:

$$\mathbb E[z]=\mathbb E\!\left[\sum_{j=1}^{n_{\rm in}}W_ja_j\right]=\sum_{j=1}^{n_{\rm in}}\mathbb E[W_ja_j]=\sum_{j=1}^{n_{\rm in}}\underbrace{\mathbb E[W_j]}_{0}\mathbb E[a_j]=0.$$

Because $\mathbb E[z]=0$, the output variance equals the output second moment: $\operatorname{Var}(z)=\mathbb E[z^2]-(\mathbb E[z])^2=\mathbb E[z^2]$. Now compute $\mathbb E[z^2]$:

How variance controls forward signal scale: Because $\mathbb E[z]=0$, the mean tells us nothing about how large the numbers $z$ actually are—positive and negative preactivations cancel out whether $z\in[-10^{-4},10^{-4}]$ or $z\in[-10^4,10^4]$. The typical magnitude (root-mean-square scale) of $z$ is governed by the standard deviation $\sqrt{\operatorname{Var}(z)}=\sqrt{\mathbb E[z^2]}=\bigl(\sqrt{n_{\rm in}}\,s_W\bigr)\sqrt{q}$:

Why the recurrence tracks the second moment $\mathbb E[a_j^2]$ instead of variance $\operatorname{Var}(a_j)$: By definition, variance measures expected squared deviation around the mean $\mu_a=\mathbb E[a_j]$, whereas the second moment measures expected squared magnitude around zero. Expanding $\operatorname{Var}(a_j)=\mathbb E[(a_j-\mu_a)^2]$ connects the two:

$$\begin{aligned}\operatorname{Var}(a_j)&=\mathbb E\bigl[(a_j-\mu_a)^2\bigr]=\mathbb E\bigl[a_j^2-2\mu_aa_j+\mu_a^2\bigr]=\mathbb E[a_j^2]-2\mu_a\mathbb E[a_j]+\mu_a^2=\mathbb E[a_j^2]-\bigl(\mathbb E[a_j]\bigr)^2\\[4pt]\implies\quad\underbrace{\mathbb E[a_j^2]}_{\text{second moment}}&=\underbrace{\operatorname{Var}(a_j)}_{\text{spread around }\mu_a}+\underbrace{\bigl(\mathbb E[a_j]\bigr)^2}_{\text{squared mean offset}}.\end{aligned}$$
$$\operatorname{Var}(z)=\mathbb E[z^2]=n_{\rm in}\,s_W^2\,\mathbb E[a_j^2]=n_{\rm in}\,s_W^2\Bigl(\operatorname{Var}(a_j)+\bigl(\mathbb E[a_j]\bigr)^2\Bigr).$$

The second moment and variance coincide only when the inputs are zero-centered ($\mathbb E[a_j]=0$, as in linear layers or odd functions like $\tanh$). For non-negative activations, $\mathbb E[a_j]>0$ and the squared mean $(\mathbb E[a_j])^2$ inflates the next layer’s preactivation variance: sigmoid ($\sigma(z)\in(0,1)$) has mean $\mathbb E[a_j]=0.5$ on symmetric inputs—adding a baseline $(\mathbb E[a_j])^2=0.25$ even when signal spread $\operatorname{Var}(a_j)$ is tiny—and ReLU ($\max(0,z)\ge 0$) has $\mathbb E[a_j]>0$.

3. Compounding across depth: forward and backward

Now stack $L$ linear layers in a chain: $h_l=W_lh_{l-1}$ for $l=1,2,\dots,L$, starting from input $h_0=x$ with coordinate second moment $q_0=\mathbb E[h_{0,j}^2]$. Suppose every layer has width $n$ ($n_{\rm in}=n$) and each weight matrix $W_l\in\mathbb R^{n\times n}$ has independent zero-mean entries of variance $s_W^2$, independent of the incoming activations $h_{l-1}$.

Let $q_l=\mathbb E[h_{l,i}^2]$ denote the second moment of a coordinate after layer $l$. Applying our single-layer result from Section 2 to layer $l$—where $h_{l,i}=\sum_{j=1}^n W_{l,ij}h_{l-1,j}$ sums $n$ inputs of second moment $q_{l-1}$—shows that each layer multiplies the signal’s second moment by the per-layer factor $c=ns_W^2$. Unrolling that recurrence from layer $1$ through layer $L$ multiplies by $c$ at every step:

$$\begin{aligned}q_1&=\mathbb E[h_{1,i}^2]=(n\,s_W^2)\,q_0=c\,q_0,\\q_2&=\mathbb E[h_{2,i}^2]=c\,q_1=c(c\,q_0)=c^2q_0,\\&\;\;\vdots\\q_L&=c\,q_{L-1}=\underbrace{c\cdot c\cdots c}_{L\text{ layers}}\,q_0=c^Lq_0=(n\,s_W^2)^Lq_0.\end{aligned}$$

Because depth $L$ sits in the exponent, the signal scale forms a geometric progression with ratio $c=ns_W^2$, splitting initialization into three regimes:

Backward pass: why $n_{\rm out}$ appears by the exact same derivation

To keep layer numbers and neuron numbers completely distinct, write the layer index in the superscript—with left layer $(l)$ containing $n_{\rm in}$ neurons (indexed by $j=1,\dots,n_{\rm in}$) and right layer $(l+1)$ containing $n_{\rm out}$ neurons (indexed by $i=1,\dots,n_{\rm out}$). The weight matrix sitting between them belongs to the right layer, $W^{(l+1)}\in\mathbb R^{n_{\rm out}\times n_{\rm in}}$, where $i$ picks the neuron in the right layer $(l+1)$ and $j$ picks the neuron in the left layer $(l)$:

Notice that $\delta_j^{(l)}=\sum_{i=1}^{n_{\rm out}}W_{i,j}^{(l+1)}\delta_i^{(l+1)}$ has the exact same mathematical structure as $z_i^{(l+1)}=\sum_{j=1}^{n_{\rm in}}W_{i,j}^{(l+1)}a_j^{(l)}$—using the right layer’s weights $W^{(l+1)}$, with the sum running over the $n_{\rm out}$ neurons $i=1,\dots,n_{\rm out}$ of the right layer instead of the $n_{\rm in}$ neurons $j=1,\dots,n_{\rm in}$ of the left layer. Letting $\tilde q_{l+1}=\mathbb E[(\delta_i^{(l+1)})^2]$ be the gradient second moment at the right layer $(l+1)$, with $\mathbb E[W_{i,j}^{(l+1)}]=0$ and $\operatorname{Var}(W_{i,j}^{(l+1)})=\mathbb E[(W_{i,j}^{(l+1)})^2]=s_W^2$ independent of $\delta_i^{(l+1)}$, we follow the exact same three steps:

Unrolling this backward recurrence $\tilde q_l=(n_{\rm out}\,s_W^2)\,\tilde q_{l+1}$ across $L$ layers from the output gradient $\tilde q_L$ back to the input gradient $\tilde q_0$ gives $\tilde q_0=(n_{\rm out}\,s_W^2)^L\tilde q_L$. Requiring the backward gradient variance to stay constant across layers ($\tilde q_l=\tilde q_{l+1}$) sets the backward multiplier equal to $1$:

$$\begin{aligned}n_{\rm out}\cdot\operatorname{Var}(W)&=1\\\operatorname{Var}(W)=s_W^2&=\frac{1}{n_{\rm out}}\\\sqrt{\operatorname{Var}(W)}=s_W&=\sqrt{\frac{1}{n_{\rm out}}}=\frac{1}{\sqrt{n_{\rm out}}}.\end{aligned}$$

Resolving the conflict when $n_{\rm in}\ne n_{\rm out}$

Unless a layer has equal input and output widths ($n_{\rm in}=n_{\rm out}$), the forward and backward conditions give two conflicting equations for the same weight variance $\operatorname{Var}(W)=s_W^2$:

$$\text{Forward wants: }\operatorname{Var}(W)=s_W^2=\frac{1}{n_{\rm in}},\qquad\text{Backward wants: }\operatorname{Var}(W)=s_W^2=\frac{1}{n_{\rm out}}.$$

Because a single weight matrix $W^{(l+1)}$ cannot satisfy both at once when $n_{\rm in}\ne n_{\rm out}$, Xavier (Glorot) initialization compromises by averaging the two fan counts $\bigl(n_{\rm avg}=\frac{n_{\rm in}+n_{\rm out}}{2}\bigr)$:

$$\begin{aligned}\left(\frac{n_{\rm in}+n_{\rm out}}{2}\right)\cdot\operatorname{Var}(W)&=1\\\operatorname{Var}(W)=s_W^2&=\frac{2}{n_{\rm in}+n_{\rm out}}\\\sqrt{\operatorname{Var}(W)}=s_W&=\sqrt{\frac{2}{n_{\rm in}+n_{\rm out}}}.\end{aligned}$$

Sources

Glorot and Bengio, Understanding the Difficulty of Training Deep Feedforward Neural Networks; He et al., Delving Deep into Rectifiers; Saxe et al., Deep Linear Network Dynamics.