Causes of the Vanishing Gradient Problem
The Vanishing Gradient Problem represents one of the fundamental challenges in training deep neural networks. It manifests when, during backpropagation, the gradients computed in the initial layers of the network become very small, making the weight updates ineffective and compromising the learning ability of the model.
This problem was one of the main obstacles to the development of deep architectures until the introduction of Residual Networks (ResNet), specifically designed to mitigate its effects. Through the use of residual connections, ResNet allows gradients to flow more easily even in very deep models, facilitating stable and efficient training. (For a deeper dive into the ResNet architecture, we recommend our article)
At AIknow, we systematically address the Vanishing Gradient Problem by adopting proven solutions such as nonlinear activation functions (ReLU), optimized weight initializations, and architectures with residual pathways, thus developing reliable and high-performance models.
Now, let’s analyze the main causes behind the Vanishing Gradient Problem in deep neural networks.
1. Sigmoid or tanh activation functions
Nonlinear activation functions like sigmoid and hyperbolic tangent have historically been widely used, but they have a major drawback:
their derivatives tend toward zero for very large or very small inputs.
- Sigmoid:



- Hyperbolic tangent:
The derivative is:
Again, for very large or small inputs, approaches -1 or +1, so the derivative approaches zero.
The effect is the following: gradients flowing backward become very small, almost vanishing, preventing weight updates in the initial layers.
2. Repeated multiplication of weights less than 1
During backpropagation, the gradient is multiplied by the weights of each layer. If these weights are numbers less than 1, multiplying them over many layers leads to a very small gradient.
Example: Imagine multiplying a number like 0.8 by itself 10 times:
After 10 layers, the gradient has been reduced by almost an order of magnitude.
3. Gradient propagation through many layers
In very deep networks, each layer receives a gradient smaller than the previous one.
This is a structural problem: the more layers there are, the more gradients are reduced, until those in the first layers become too small to be useful.
Effects of the Vanishing Gradient Problem
- The initial layers learn very slowly or stop learning.
- The network struggles to converge or requires very long training times.
- Weights remain almost unchanged, limiting the network’s ability to learn useful representations.
Solutions to the Vanishing Gradient Problem
Fortunately, in recent years several effective techniques have been developed to mitigate or solve the vanishing gradient problem. Below are the main ones:
1. Using Different Activation Functions
One of the most important strategies is to replace functions like sigmoid or tanh with activations that do not saturate, such as ReLU (Rectified Linear Unit):
This avoids the problem of the derivative tending to zero, ensuring a more stable gradient flow.
2. Advanced Weight Initialization
Techniques like Xavier Initialization and He Initialization have been developed to set initial weights so that gradients maintain a stable scale throughout the network. This helps prevent both the vanishing gradient and the opposite problem, called exploding gradient.
3. Batch Normalization
This technique normalizes activations within each batch during training, maintaining more stable input distributions across layers. This greatly reduces the risk of gradients being too small or too large and improves network convergence speed.
4. Residual Connections (ResNet)
Residual connections allow the gradient to bypass some layers by directly adding the initial input to the output of a block. ResNet introduces residual connections, which enable the gradient to flow more easily through the layers.
The formula for a residual connection is:
This mechanism allows the gradient to propagate directly thanks to the sum with the initial input, mitigating the vanishing gradient problem.
Practical Example of the Vanishing Gradient
Suppose we have a deep neural network using the sigmoid activation function. During backpropagation, gradients in the first layers almost completely vanish, preventing learning.
Here is an example:
import torch import torch.nn as nn # Deep network with Sigmoid activation: subject to vanishing gradient problem class VanishingNetwork(nn.Module): def __init__(self): super(VanishingNetwork, self).__init__() self.model = nn.Sequential( nn.Linear(2, 64), # First linear layer nn.Sigmoid(), # Sigmoid activation function nn.Linear(64, 64), nn.Sigmoid(), nn.Linear(64, 64), nn.Sigmoid(), nn.Linear(64, 1), nn.Sigmoid() # Final output between 0 and 1 ) def forward(self, x): return self.model(x) # Deep network with ReLU activation: avoids vanishing gradient class NoVanishingNetwork(nn.Module): def __init__(self): super(NoVanishingNetwork, self).__init__() self.model = nn.Sequential( nn.Linear(2, 64), # First linear layer nn.ReLU(), # ReLU activation function nn.Linear(64, 64), nn.ReLU(), nn.Linear(64, 64), nn.ReLU(), nn.Linear(64, 1), nn.Sigmoid() # Final output between 0 and 1 ) def forward(self, x): return self.model(x) # Example input with gradients enabled x = torch.tensor([[0.5, -0.5]], requires_grad=True) # Run model with Sigmoid activation vanishing_net = VanishingNetwork() output1 = vanishing_net(x) output1.backward(retain_graph=True) print("Gradient wrt input (Sigmoid):", x.grad.clone()) # Zero gradient before second run x.grad.zero_() # Run model with ReLU activation relu_net = NoVanishingNetwork() output2 = relu_net(x) output2.backward() print("Gradient wrt input (ReLU):", x.grad)
This simple experiment highlights the practical differences between a neural network using the Sigmoid activation and one using ReLU. In the first case, the gradients calculated with respect to the input are significantly smaller due to the nature of the Sigmoid derivative, which tends toward values very close to zero for extreme inputs. This behavior makes effective weight updating in the layers closest to the input difficult, compromising the learning ability of the entire network, especially if very deep.
The use of the ReLU function, on the other hand, allows to maintain more consistent gradients throughout the network. This makes optimization more stable and faster, facilitating the training of deep architectures. This is one of the main reasons why ReLU has become the default activation function in modern deep learning.
The example thus concretely demonstrates how the choice of activation directly influences gradient propagation and, consequently, the overall model performance.
Gradient Flow Visualization
Considerations
The vanishing gradient problem is not only a technical obstacle but also strongly influences architectures and training effectiveness. Very deep networks, like those used in many modern deep learning models, are sensitive to this phenomenon. The ability to mitigate this problem has led to the development of more robust architectures such as ResNet and DenseNet, which have become standard in many applications.
Despite available solutions, the vanishing gradient problem remains a challenge, especially for those new to deep learning. It is crucial to adopt the right techniques, monitor gradients, and choose the architecture best suited to the problem at hand.
Conclusions
The vanishing gradient problem long hindered the evolution of deep learning. However, thanks to techniques like ReLU, residual connections, and batch normalization, it is now possible to train deep neural networks without encountering the problems that once prevented their success.
It remains essential to recognize and diagnose this problem during training, especially when signs of slow or stagnant learning start to appear. In such cases, it is always good practice to monitor gradient flow, explore possible solutions such as residual architectures, and optimize the training process.
If your project requires advanced deep learning expertise or you want to learn more about solving gradient propagation issues, contact us: our team is ready to support you with tailored solutions for your needs.