Firoj Paudel

Understanding Vanishing and Exploding Gradient Problems

A deep mathematical look into gradient instability during backpropagation in deep neural networks and recurrent architectures.

outputinputthresholdNaN‖W‖ < 1 · vanishing‖W‖ > 1 · explodinggradient clipping

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 .

Sigmoid and its derivative: red is the sigmoid function, violet its derivative.
Sigmoid and its derivative: red is the sigmoid function, violet its derivative.
Tanh and its derivative: red is the tanh function, green its derivative.
Tanh and its derivative: red is the tanh function, green its derivative.

Practical Mitigations

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