Recommended resources
The freely available resources this lesson will direct you to.
- L11.6 Xavier Glorot and Kaiming He Initializationwww.youtube.com
- Weight Initialization in a Deep Network (C2W1L11)www.youtube.com
- Weight Initialization for Deep Learning Neural Networkswww.machinelearningmastery.com
- Why Weight Initialization Is Important in Deep Learning (Xavier ...www.aryanupadhyay.com
Hello! Welcome to your next lesson on training deep neural networks.
Introduction
In our last lesson, we explored the role of optimizers like Adam and SGD, which are the engines that drive learning by updating model weights to minimize loss. We saw that the training process is an iterative search for the best set of weights. This raises a fundamental question: where does this search begin?
This lesson focuses on weight initialization, the process of setting the initial values for the weights in a neural network. It might seem like a minor detail, but as you'll see, the choice of initial weights is critical. A poor choice can prevent a deep network from learning at all, while a good choice can significantly speed up convergence and improve performance.
Our goal is to explain the purpose of weight initialization strategies, focusing on two modern standards: Xavier and He initialization. We will first explore what happens when initialization goes wrong, and then see how these principled methods provide a solution.
1. The Perils of Poor Initialization
Before we learn the right way to initialize weights, it's crucial to understand why simple approaches fail. Let's examine a few common but flawed strategies.
The Symmetry Problem: Zero or Constant Initialization
What if we initialize all weights to zero? Or to a constant value like 0.5? This seems simple, but it creates a fatal issue known as the symmetry problem.
If all weights are the same, every neuron in a given layer will receive the same inputs, perform the same computation, and produce the same output. During backpropagation, they will also receive the same gradient and thus undergo the exact same update. This symmetry is never broken.

This means that no matter how many neurons you have in a layer, they all learn the same thing. The network's ability to learn complex, hierarchical features is completely crippled.
The Gradient Problem: Small or Large Random Values
A natural next step is to break the symmetry by using small random numbers. While this solves the symmetry problem, it introduces new issues in deep networks:
- Vanishing Gradients: If weights are too small, the weighted sum of inputs will be small. For activation functions like
tanhorsigmoid, this keeps the activations near zero. As this small signal propagates through many layers, it diminishes further, causing the gradients during backpropagation to become vanishingly small. The early layers of the network learn extremely slowly, if at all. - Exploding Gradients: If weights are too large, the opposite happens. The activations can grow exponentially with each layer, leading to enormous values. This causes the gradients to become huge, making the weight updates unstable and causing the training process to diverge.
- Saturation: With large weights, the inputs to
sigmoidortanhfunctions can be far from zero, pushing the output to the "saturated" flat parts of the curve (near -1/1 fortanh, or 0/1 forsigmoid). In these regions, the gradient is almost zero, which again stalls learning.

To understand these failure modes in more detail, let's read an article that explains them clearly.
Why Weight Initialization Is Important in Deep Learning (Xavier vs He Explained)
The article 'Why Weight Initialization Is Important in Deep Learning' by Aryan Upadhyay provides excellent explanations of what goes wrong with naive initialization strategies.
Please read from the beginning down to the end of the section 'Case 4: Random Initialization (Large Values)'. Focus on understanding the distinct problems caused by zero, constant, small random, and large random initialization.
2. The Solution: Controlling Signal Variance
The core insight behind modern initialization techniques is that we need to keep the variance of the activations and gradients consistent as they propagate through the network. We want to avoid the signal either dying out (vanishing) or blowing up (exploding).
The key is to scale the initial weights based on the number of input and output neurons for a layer. We define:
fan_in: The number of input connections to a neuron (i.e., the number of neurons in the previous layer).fan_out: The number of output connections from a neuron (i.e., the number of neurons in the current layer).
The intuition is simple: if a neuron has a large number of inputs (fan_in), the random weights connected to it should be smaller to keep the variance of its output under control. This insight is the foundation for both Xavier and He initialization.
3. Xavier (Glorot) Initialization
Xavier initialization, named after Xavier Glorot, was designed to work well with saturating activation functions like tanh and sigmoid. It balances the fan_in and fan_out to ensure the variance of the activations and backpropagated gradients remains roughly constant from layer to layer.
The strategy is to draw weights from a distribution with a mean of 0 and a specific variance.
To get a quick and clear overview of this method, let's watch a short video.
Weight Initialization in a Deep Network (C2W1L11)
This video from DeepLearningAI, featuring Andrew Ng, provides a concise explanation of the motivation behind principled weight initialization.
Watch the segments from 0:00-1:44 and 3:50-4:43. Focus on: The core problem of vanishing/exploding gradients. The intuition that weights should be smaller when n (the number of inputs or fan_in) is larger. The specific formula variant recommended for tanh activation.
As you saw, the goal is to set the variance of the weights based on the layer's size. The two common forms of Xavier initialization are:
- Xavier Normal: Draw weights from a normal distribution with mean 0 and variance .
- Xavier Uniform: Draw weights from a uniform distribution , where .
This method was a significant step forward, but its derivation relies on assumptions (like linear activations) that don't hold true for the most common activation function used today: ReLU.
4. He Initialization
When using the Rectified Linear Unit (ReLU) activation function, a different approach is needed. Since ReLU sets all negative inputs to zero, it effectively "kills" about half of the activations. This changes the variance of the outputs in a way that Xavier initialization doesn't account for, which can lead to vanishing gradients again.
He initialization, named after Kaiming He, was developed specifically for ReLU and its variants (like Leaky ReLU). It compensates for the zeroing effect of ReLU by using a larger variance for the weights.
Let's see how this method is derived and why it's better for ReLU.
L11.6 Xavier Glorot and Kaiming He Initialization
Now, let's watch a more detailed video from Sebastian Raschka that first visualizes the benefits of Xavier initialization and then introduces the He initialization adaptation for ReLU.
Watch the entire video (around 11 minutes). For the first part (0:00 - 9:54), pay close attention to the plots showing how Xavier initialization helps maintain a healthy gradient flow across layers. For the second part (9:54 - 11:45), focus on why ReLU requires a different initialization scheme and how the He formula is adapted from Xavier.
The formulas for He initialization are similar to Xavier's but only consider fan_in:
- He Normal: Draw weights from a normal distribution with mean 0 and variance .
- He Uniform: Draw weights from a uniform distribution , where .
Notice the variance is roughly double that of Xavier initialization, which helps keep the signal strong enough when passing through ReLU layers.
For a final recap and to see the formulas laid out clearly, this article is an excellent reference.
Weight Initialization for Deep Learning Neural Networks
The article 'Weight Initialization for Deep Learning Neural Networks' from Machine Learning Mastery is a great practical guide that summarizes the formulas for both Xavier and He initialization.
Please read the sections 'Weight Initialization for Sigmoid and Tanh' and 'Weight Initialization for ReLU'. You don't need to run the code, but pay attention to the formulas presented for Xavier and He initialization and how they are implemented.
Conclusion
In this lesson, we uncovered why careful weight initialization is not just a minor tweak but a fundamental requirement for training deep neural networks.
Key Takeaways:
- Bad initialization is fatal: Initializing weights to zero or a constant causes a symmetry problem, crippling the network. Initializing them randomly but improperly (too small or too large) leads to vanishing or exploding gradients.
- The solution is variance control: The goal of modern initialization is to set the initial weights such that the variance of the signal (activations and gradients) remains stable as it propagates through the network.
- Xavier (Glorot) Initialization is designed for saturating activation functions like
tanhandsigmoid. It scales weights based on both the number of input (fan_in) and output (fan_out) neurons. - He Initialization is the standard for ReLU and its variants. It accounts for ReLU's non-linearity by using a larger variance, typically based only on
fan_in.
As a simple rule of thumb: if you are using ReLU activations, start with He initialization. If you are using tanh or sigmoid, use Xavier. Most modern deep learning frameworks make these the default choices for their respective layers.
In our next lesson, we will continue exploring techniques to improve training by looking at learning rate scheduling, a method to dynamically adjust the learning rate during training to achieve faster convergence and better final performance.