Weight Initialization
Starting right — why proper initialization is critical for training deep networks
Why Initialization Matters
Weight initialization determines the starting point for gradient descent. Poor initialization can cause:
- Training failure (no learning at all)
- Vanishing/exploding activations
- Extremely slow convergence
Symmetry Breaking
If all weights are initialized identically, all neurons in a layer compute the same output, receive the same gradient, and update identically. They remain symmetric forever.
Result: A layer with 100 neurons behaves like a layer with 1 neuron.
Solution: Random initialization breaks symmetry — each neuron learns different features.
Bad Initializations
All Zeros
W = np.zeros((input_dim, output_dim))Problem: All neurons output zero, all gradients are zero, nothing ever changes.
All Same Value
W = np.ones((input_dim, output_dim)) * 0.1Problem: Symmetry is never broken — neurons stay identical.
Too Large
W = np.random.randn(input_dim, output_dim) * 10Problem: Activations explode through layers, gradients explode, NaN losses.
Too Small
W = np.random.randn(input_dim, output_dim) * 0.001Problem: Activations shrink to zero, gradients vanish, no learning.
The Variance Problem
Consider a layer:
If weights and inputs are independent with zero mean:
Through Multiple Layers
For a network with
If
If
Goal: Keep

Xavier/Glorot Initialization
For sigmoid/tanh activations (Glorot & Bengio, 2010)
Derivation
To maintain variance through both forward and backward passes:
- Forward:
- Backward:
Compromise: Use the harmonic mean:
Implementation
# Xavier uniform
limit = np.sqrt(6 / (n_in + n_out))
W = np.random.uniform(-limit, limit, (n_in, n_out))
# Xavier normal
std = np.sqrt(2 / (n_in + n_out))
W = np.random.randn(n_in, n_out) * stdWhen to Use
- Sigmoid activations
- Tanh activations
- Linear activations
He/Kaiming Initialization
For ReLU activations (He et al., 2015)
Why Xavier Fails for ReLU
ReLU zeros out ~50% of activations on average. If input variance is
This extra factor of 1/2 causes variance to shrink through layers with Xavier init.
Derivation
To compensate for ReLU killing half the values:
The factor of 2 accounts for ReLU's halving effect.
Implementation
# He uniform
limit = np.sqrt(6 / n_in)
W = np.random.uniform(-limit, limit, (n_in, n_out))
# He normal (most common)
std = np.sqrt(2 / n_in)
W = np.random.randn(n_in, n_out) * stdWhen to Use
- ReLU activations
- Leaky ReLU
- ELU
- GELU (usually works well)
Other Initialization Schemes
LeCun Initialization
For SELU (self-normalizing) activations:
Orthogonal Initialization
Initialize weight matrices as orthogonal matrices:
W, _ = np.linalg.qr(np.random.randn(n_in, n_out))Benefits: Preserves gradient norm during backprop, useful for RNNs.
LSUV (Layer-Sequential Unit-Variance)
- Initialize with orthogonal weights
- Forward pass on a batch
- Rescale each layer to have unit variance
Benefit: Data-dependent initialization, works for any architecture.
Framework Defaults
Modern frameworks have sensible defaults:
| Framework | Default for Linear/Dense |
|---|---|
| PyTorch | Kaiming uniform (for Linear), Xavier for others |
| TensorFlow/Keras | Glorot uniform |
| JAX | Lecun normal |
Usually you don't need to change these — but knowing why they work helps debugging.
Diagnosing Initialization Problems
Signs of Bad Initialization
| Symptom | Likely Cause |
|---|---|
| Loss is NaN | Exploding activations (init too large) |
| Loss doesn't decrease | Vanishing gradients (init too small) or symmetry |
| All outputs are same | Symmetry not broken |
| Some neurons never activate | Dead ReLUs (init caused negative region) |
Debugging Steps
- Print activation statistics at each layer:
for name, layer in model.named_modules():
print(f"{name}: mean={activations.mean():.4f}, std={activations.std():.4f}")- Check gradient norms:
for name, param in model.named_parameters():
if param.grad is not None:
print(f"{name}: grad_norm={param.grad.norm():.6f}")- Visualize activation distributions:

Practical Guidance
Rules of Thumb
| Activation | Initialization | Formula |
|---|---|---|
| Sigmoid/Tanh | Xavier | |
| ReLU/variants | He | |
| SELU | LeCun | |
| Linear | Xavier |
Special Cases
- ResNets: Scale final layer of each residual block by
or - Transformers: Often use
scaling - Batch Norm: Initialization matters less because BN normalizes
Interview Questions
Q1: "Why can't we initialize all weights to zero?"
All neurons would compute the same output, because they have identical weights. During backpropagation, they all receive the same gradient and update identically. This symmetry is never broken — the neurons remain identical forever.
Result: A layer with 100 neurons effectively acts like a single neuron. The network cannot learn diverse features.
Solution: Random initialization breaks symmetry. Each neuron starts with different weights, computes different outputs, receives different gradients, and learns different features.
Note: Biases can be initialized to zero because they don't break symmetry (each neuron still has unique weights).
Q2: "Derive He initialization for ReLU."
Goal: Keep activation variance stable through layers.
For a layer
with independent inputs: ReLU's effect:
(zeros half the values) For stable variance through layers:
He initialization: Sample from
or The factor of 2 compensates for ReLU killing half the activations.
Q3: "How would you debug a network that isn't learning?"
Step 1: Check activation distributions at each layer
- Near zero everywhere → init too small, vanishing activations
- Very large/NaN → init too large, exploding activations
- All same value → symmetry not broken
Step 2: Check gradient norms
- Very small (< 1e-7) → vanishing gradients
- Very large or NaN → exploding gradients
Step 3: Verify initialization matches activation
- ReLU needs He init (
) - Sigmoid/Tanh needs Xavier (
) Step 4: Other checks
- Learning rate too high/low?
- Loss function appropriate for task?
- Data preprocessing correct?
- Bug in model architecture?
Quick fix: Add BatchNorm — it's more forgiving of initialization.
Key Takeaways
Random initialization breaks symmetry — essential for neurons to learn different features.
Variance must be preserved through layers to prevent vanishing/exploding activations.
Use He for ReLU (
) — the factor of 2 compensates for ReLU killing half the values. Use Xavier for sigmoid/tanh (
) — balances forward and backward variance. Diagnosis: Print activation means/stds and gradient norms layer by layer to identify problems.