# On the difficulty of training Recurrent Neural Networks

Gradient clipping and a soft penalty fix exploding and vanishing gradients in recurrent networks

Razvan Pascanu, Tomas Mikolov, Yoshua Bengio · arXiv · 2012-11-21

- **Problem** Recurrent networks trained with backpropagation through time see gradients explode or vanish over long sequences. Both failures come from the same product, so training struggles to link distant events.
- **Method** The authors rescale gradients above a fixed norm threshold. For vanishing gradients they add a penalty that keeps error norms steady across steps.
- **Results** SGD-CR reached a 100% success rate on temporal order sequences up to 200 steps, where SGD and SGD-C failed on longer sequences.

## Why gradients break over long sequences

A recurrent network carries a hidden state from one step to the next, so earlier inputs can shape later predictions. Training it with Backpropagation Through Time means unrolling the model into a deep network with one copy per time step. The total gradient is a sum of temporal contributions, and each one contains a product of Jacobian matrices that spans the gap between two steps.

When that product grows, the exploding gradients problem appears; when it shrinks, the vanishing gradients problem appears.

A sudden norm spike can ruin a single update, while vanishing long-term terms leave the model unable to link events that are far apart. Both failures come from the same product, which is why the paper treats them together.

## Clipping and a soft norm penalty

For exploding gradients, the key idea is to rescale any gradient whose norm passes a fixed threshold back down to that threshold before the update. For vanishing gradients the authors don't clip anything; they add a penalty to the training objective instead, because increasing the norm of the Jacobian products can't always follow a descent direction of the error.

The penalty compares the norm of the error signal after one Jacobian step with the norm before it, and it is minimized when that ratio is one. The authors use only the immediate partial derivative with respect to the recurrent weights, treating the error and the state as constants, which keeps the computation cheap. Because it is a preference rather than a hard rule, it does not guarantee that the error norm stays fixed.

Clipping keeps the direction of the step and only caps its length, which is simple to implement and cheap to compute. It adds one hyper-parameter, the threshold, and the authors suggest setting it from statistics of the average norm over many updates.

## Why the linear analysis predicts blow-up

For a linear version of the model, the analysis uses the power iteration method on the product of Jacobian matrices. In that case the largest eigenvalue λ1 of the recurrent weight matrix decides the outcome: a value below 1 makes long-term components vanish, and a value above 1 is needed for gradients to explode.

For nonlinear σ whose derivative is bounded by γ, the authors prove that a λ1 below 1/γ is sufficient for the vanishing gradient problem. The bound is γ = 1 for tanh and γ = 1/4 for sigmoid, so the sigmoid case allows a larger recurrent eigenvalue before the explosion condition is reached.

The authors also view the model as a dynamical system, where bifurcations and crossings of basin boundaries could make the state jump. They hypothesize that when gradients explode along a direction, the curvature also grows along that direction, which creates a steep wall in the error surface.

## Temporal order results

The temporal order task places two symbols at separated points in a long sequence of distractor symbols and asks for their order. The authors compare SGD, SGD-C and SGD-CR by success rate as the sequence length grows on a log scale.

Neither SGD nor SGD-C solves sequences longer than 20, and the authors attribute this to vanishing gradients. As long as vanishing isn't the main obstacle, adding the exploding-gradient fix raises the success rate, which the authors read as evidence that exploding gradients are tied to tasks needing long memory.

SGD-CR reached a 100% success rate for sequences up to 200 steps, the maximum used by Martens and Sutskever. A single model trained on lengths from 50 to 200 also generalized to sequences twice as long as those seen in training.

## Other pathological tasks

SGD-CR also reached 100% on most of the other pathological tasks from Hochreiter and Schmidhuber, including addition, multiplication and noiseless memorization. For the first four of those problems a single model covered lengths up to 200, while noiseless memorization used a separate model for each length. The random permutation problem was the exception, and only one of eight trials succeeded.

The authors report higher success rates than Martens and Sutskever and longer sequences than Hochreiter and Schmidhuber.

## Music and language results

On Piano-midi.de, test negative log likelihood per time step fell from 7.56 under SGD to 7.46 with SGD-CR. On Nottingham it fell from 3.80 to 3.46, while on MuseData the authors report matching the state of the art, which uses a different architecture.

On Penn Treebank next character prediction, test entropy went from 1.50 bits per character with SGD to 1.42 with clipping and 1.41 with SGD-CR. Because the training error also improves, the authors conclude that clipping fixes an optimization issue rather than acting as a regularizer.

## Limitations

The regularizer only prefers solutions that preserve the error norm, so it gives no guarantee. The authors note that preventing vanishing gradients can push the model toward basin boundaries, making explosions more likely, so clipping stays necessary. Teacher forcing needs a target defined at every time step. Echo State Networks avoid the gradient problem by not learning their recurrent weights, but they struggle with long-term dependencies.

In the authors' experiments, training was not very sensitive to the clipping threshold for a given task and model size.

## Paper info

- **Authors**: Razvan Pascanu, Tomas Mikolov, Yoshua Bengio
- **Venue**: arXiv · Preprint
- **First published**: 2012-11-21
- **Added**: 2026-11-12
- **Updated**: 2013-2-16
- **Version**: v2
- **arXiv**: 1211.5063
- **Category**: cs.LG
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1211.5063v2) · [PDF ↗](https://arxiv.org/pdf/1211.5063v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Razvan Pascanu, Tomas Mikolov, Yoshua Bengio (2012). On the difficulty of training Recurrent Neural Networks. arXiv:1211.5063v2. https://arxiv.org/abs/1211.5063v2

**BibTeX**

```
@misc{pascanu2012difficulty,
  title = {{On the difficulty of training Recurrent Neural Networks}},
  author = {Razvan Pascanu and Tomas Mikolov and Yoshua Bengio},
  year = {2012},
  eprint = {1211.5063},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1211.5063v2}
}
```

## Other paper commentary

- [Spectral Networks and Locally Connected Networks on Graphs](https://refivu.com/en/papers/c8d7ac6f-ca53-43f2-b5f6-9ac71d5ca32d-spectral-networks-and-locally-connected-networks-on-graphs.md)
- [An Introduction to Convolutional Neural Networks](https://refivu.com/en/papers/6b236b8c-8750-484a-8c31-87433f51f2eb-an-introduction-to-convolutional-neural-networks.md)
- [Matching Networks for One Shot Learning](https://refivu.com/en/papers/b9fc7556-8641-4de5-90e9-278f5122412f-matching-networks-for-one-shot-learning.md)
- [LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation](https://refivu.com/en/papers/ce104c95-75b4-4033-900a-57eef9818488-lightgcn-simplifying-and-powering-graph-convolution-network.md)
- [Unsupervised Domain Adaptation by Backpropagation](https://refivu.com/en/papers/5b06ce85-04aa-40bd-a8ba-094e15a092f1-unsupervised-domain-adaptation-by-backpropagation.md)
- [Spatial Transformer Networks](https://refivu.com/en/papers/6eb29eca-41eb-4d69-ace3-032bf11562a8-spatial-transformer-networks.md)
- [BERTopic: Neural topic modeling with a class-based TF-IDF procedure](https://refivu.com/en/papers/3eb59114-35a2-4294-982a-129e3bf9019b-bertopic-neural-topic-modeling-with-a-class-based.md)
- [Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference](https://refivu.com/en/papers/07bb92b6-cd63-4ab5-ab99-88473c074df7-quantization-and-training-of-neural-networks-for-efficient.md)
- [Striving for Simplicity: The All Convolutional Net](https://refivu.com/en/papers/a95bd630-88c1-480e-8223-b0666111b3e5-striving-for-simplicity-the-all-convolutional-net.md)
- [Program Synthesis with Large Language Models](https://refivu.com/en/papers/91ec5a25-4d41-4e97-96c5-09d1f9e9480e-program-synthesis-with-large-language-models.md)
- [A Survey on Hallucination in Large Language Models: Principles, Taxonomy, Challenges, and Open Questions](https://refivu.com/en/papers/c1cfd3a7-67eb-4e85-ad04-a8242f75f562-a-survey-on-hallucination-in-large-language-models.md)
- [Deep Visual-Semantic Alignments for Generating Image Descriptions](https://refivu.com/en/papers/f477c9f4-e68d-4089-85ea-7f883a691c98-deep-visual-semantic-alignments-for-generating-image.md)

## Terms in this paper

- [LSTM](https://refivu.com/en/terms/ba10547646d9-lstm)
- [Success rate](https://refivu.com/en/terms/0964df1dc5eb-success-rate)
- [recurrent neural network](https://refivu.com/en/terms/7df8352fc823-recurrent-neural-network)
- [Penn Treebank](https://refivu.com/en/terms/fffc021679a8-penn-treebank)
- [backpropagation through time](https://refivu.com/en/terms/46e13bff8275-backpropagation-through-time)
- [negative log likelihood](https://refivu.com/en/terms/339ecb7aa325-negative-log-likelihood)
- [power iteration method](https://refivu.com/en/terms/527229df7e20-power-iteration-method)
- [teacher forcing](https://refivu.com/en/terms/5af8c5103329-teacher-forcing)
- [norm clipping](https://refivu.com/en/terms/2bbdbfbca6b9-norm-clipping)
- [Nottingham](https://refivu.com/en/terms/9b7dcaa7beab-nottingham)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/4d1ee0a2-985d-499a-b4ad-403b5731bcd8-on-the-difficulty-of-training-recurrent-neural-networks)
