Vanishing/Exploding Gradients

Home Glossary Item Vanishing/Exploding Gradients
« Back to Glossary Index

Vanishing and exploding gradients are optimization issues that arise during the training of deep neural networks when the gradients used to update model parameters become either excessively small or excessively large. These phenomena occur as the error signal is propagated backward through the network layers, potentially causing the network to stop learning effectively or to become numerically unstable.

How it works

Neural networks learn by adjusting their internal parameters to minimize a loss function. This adjustment process relies on backpropagation, an algorithm that calculates the gradient of the loss with respect to each parameter. The gradient indicates the direction and magnitude of the change needed to reduce the error. In a deep network with many layers, the gradient for an earlier layer is computed as a product of derivatives from all subsequent layers. This chain rule multiplication is the root cause of both vanishing and exploding gradients.

Vanishing gradients occur when the values of these derivatives are less than one. As the gradient signal passes through each successive layer during backpropagation, it is multiplied by these small values. Consequently, the gradient magnitude shrinks exponentially as it moves toward the earlier layers. When the gradient becomes extremely small, the updates to the weights in the initial layers become negligible. This results in slow or stagnant learning, as the network struggles to adjust its early representations, effectively preventing the model from capturing complex relationships in the data.

Exploding gradients are the opposite phenomenon. They occur when the derivatives involved in the chain rule are greater than one. As the gradient propagates backward, these values multiply together, causing the gradient magnitude to grow exponentially. When the gradient becomes excessively large, the model parameters are updated too drastically. This leads to unstable training, where the loss function fluctuates wildly or diverges entirely, rendering the training process ineffective. Both issues are particularly problematic in very deep networks or when specific activation functions are used, as these factors influence the magnitude of the derivatives in the chain rule.

Where it is used

These issues are most commonly encountered in deep neural architectures where information must be transmitted across many layers. They are particularly relevant in recurrent neural networks (RNNs), which process sequential data by passing information through time steps. In RNNs, the same weights are applied repeatedly, amplifying the multiplicative effect of the derivatives over long sequences. This makes RNNs highly susceptible to vanishing gradients when trying to learn long-term dependencies.

Deep feed-forward networks are also subject to these problems. As the number of hidden layers increases, the cumulative effect of multiplying derivatives across all layers becomes more pronounced. If the network is deep enough, the gradient signal may vanish before reaching the first layer, or explode before reaching the final layer. The choice of activation function plays a critical role here; functions with derivatives that saturate (approach zero) or grow unbounded can exacerbate these conditions.

Training stability is a primary concern in any setting where deep architectures are employed. The phenomenon affects the convergence of the training process, meaning the network may fail to reach an optimal state. It limits the network’s ability to learn hierarchical features, as the early layers, which typically capture low-level features, may remain largely untrained if the gradient signal vanishes before reaching them.

Limitations and trade-offs

The primary limitation of vanishing and exploding gradients is that they hinder the training of deep networks, making it difficult to scale depth without careful intervention. Without mitigation, deep networks may perform no better than shallow ones because the early layers cannot learn. This limits the model’s capacity to capture complex, hierarchical representations of data.

Mitigation strategies often involve trade-offs. Careful architecture design, such as using specific activation functions or residual connections, can help preserve gradient flow but may increase model complexity. Weight initialization techniques must be carefully tuned to ensure that the initial derivatives are neither too small nor too large, which can be sensitive to the specific data distribution. Gradient clipping, a method that limits the maximum magnitude of gradients, can prevent exploding gradients but may introduce bias if the clipping threshold is set too low, potentially discarding useful signal information. These solutions address the symptoms but require additional hyperparameter tuning and architectural decisions.

Related terms

  • Back Propagation – The algorithm that computes gradients and is the direct mechanism through which vanishing and exploding gradients occur.
  • Activation Function – Functions like sigmoid or tanh have derivatives that often cause gradients to vanish, while others like ReLU help mitigate this.
  • Recurrent Neural Networks – A class of networks particularly prone to vanishing gradients due to the repeated multiplication of weights over time steps.
  • Deep Learning – The field where these gradient issues are most prominent due to the use of many hidden layers.
  • Model Parameter – The weights and biases that are updated by the gradient; their updates become negligible or excessive during these phenomena.
« Back to Glossary Index
Eugene Serbin

Systems Analyst and AI Engineer, Semalt

Eugene Serbin is a systems analyst and AI engineer at Semalt. He graduated with honours from Kharkiv National University of Radio Electronics in 2005, specialising in intelligent decision-making systems, and holds a second degree from the same university in economic cybernetics. He writes and edits the AI research summaries, applied machine learning explainers and the glossary on ai-magazine.com.