Understanding Vanishing and Exploding Gradient Problems
A deep mathematical look into gradient instability during backpropagation in deep neural networks and recurrent architectures.
Originally published on Medium by Firoj Paudel.
As neural network architectures grow deeper, training stability becomes a central bottleneck. Two fundamental phenomena, vanishing gradients and exploding gradients, can stall or completely destabilize gradient-based optimization algorithms like SGD and Adam.
The Mathematical Origin
During backpropagation, the loss gradient with respect to weights in an early layer is calculated using the chain rule:
Notice the product term .
- Vanishing Gradients: If the eigenvalues of the weight matrices or activation derivatives are less than 1, the product decays exponentially as . Early layers receive near-zero updates and stop learning.
- Exploding Gradients: If the spectral radius of the matrices exceeds 1, gradients grow exponentially, resulting in
NaNor numeric overflow.


Practical Mitigations
- Non-saturating Activations: Replace Sigmoid and Tanh with ReLU, Leaky ReLU, or GELU to avoid derivative saturation at extreme input values.
- Weight Initialization: Use He (Kaiming) initialization for ReLU networks () and Xavier (Glorot) for Tanh.
- Batch & Layer Normalization: Re-center layer inputs to maintain stable activation variance across deep stacks.
- Gradient Clipping: Cap maximum norm of gradients during backpropagation: \mathbf{g} \leftarrow \mathbf{g} \cdot \min\left(1, \frac{\text{threshold}}{\|\mathbf{g}\|}\right).
