RNNs & Sequence Models1994intermediate11 min read
Learning Long-Term Dependencies with Gradient Descent is Difficult
تعلُّم الاعتماديّات طويلة المدى بالانحدار التدريجي مهمة صعبة
Bengio, Y. · Simard, P. · Frasconi, P. — IEEE Transactions on Neural Networks
The problem
Recurrent neural networks (RNNs) can in principle learn mappings from input sequences to output sequences where relevant events are separated by long time intervals. In practice, however, -based consistently fails when the temporal gap exceeds about 10–20 steps. Practitioners observed the symptoms — training stalls, weights oscillate or diverge — but no one had explained the root cause mathematically or shown whether it was a fundamental limitation.
The contribution
A mathematical proof that gradient-based learning in RNNs faces an inherent dilemma. The gradient of the loss with respect to early time steps is a product of matrices — one per time step. If the largest of the recurrent is less than 1, these products shrink exponentially (vanishing gradients); if greater than 1, they grow exponentially (exploding gradients). Moreover, the paper shows a fundamental trade-off: for the network to store information reliably over time (using stable attractors), the same mathematical condition that ensures stability also ensures vanishing gradients. The paper also proposed alternative training strategies including simulated annealing and discrete error propagation.
The impact
This paper, alongside Hochreiter's 1991 thesis, established the problem as the central obstacle in training RNNs. It directly motivated the invention of (1997), (2013), and Xavier/Glorot initialization (2010). Every gated architecture — , Highway Networks, Residual Connections — traces its motivation back to the trade-off this paper proved. The analysis also applies to deep feedforward networks, making it a foundational result for all of deep learning.
Imagine you're the manager of a 100-floor skyscraper, and you need to pass instructions from the penthouse down to the ground floor. Each floor has a secretary who copies the message and passes it along. If every secretary writes slightly smaller — shrinking the text by 5% — by floor 50 the message is microscopic, and by floor 100 it's invisible. That's vanishing gradients.
Now imagine each secretary enlarges the text by 5%. By floor 50 the paper can't hold the message, and by floor 100 the text has exploded off the page. That's exploding gradients.
Bengio proved that RNNs face exactly this dilemma: the "secretaries" are Jacobian matrices, the "shrink/enlarge factor" is determined by eigenvalues, and there's no way to set those eigenvalues so that messages travel far without either vanishing or exploding.
The problem: why can't RNNs remember?
A processes sequences by maintaining a that gets updated at every time step. In principle, this hidden can carry information from the distant past — the network "remembers" by encoding earlier inputs into . Training uses through time (BPTT): unroll the network across all time steps and propagate the error gradient backward.
The trouble is that this backward propagation requires multiplying many Jacobian matrices together — one for each time step. By 1994, practitioners had noticed that RNNs could learn short-range patterns (5–10 steps) but failed catastrophically on anything longer. The network would either stop learning entirely (the gradient reaching early time steps was essentially zero) or become numerically unstable (the gradient exploded to infinity).
Bengio, Simard, and Frasconi set out to explain why this happens, not just observe that it happens.
The core insight: Jacobian products and eigenvalues
The hidden state evolves as , where is a nonlinear activation (like or ) and is the recurrent weight matrix. When we backpropagate from time step to an earlier step , the chain rule gives us a product of Jacobian matrices:
where each is the Jacobian at step . The key question is: what happens to this product as grows?
Think of it as compound interest, but applied to gradient magnitude. If each Jacobian matrix shrinks the gradient by a factor of 0.9, then after 50 steps the gradient is — practically zero. After 100 steps it's . The network simply cannot "see" what happened 100 steps ago.
Conversely, if each matrix amplifies by 1.1, after 50 steps the gradient is , and after 100 steps it's . The becomes numerically unstable — weights swing wildly.
Bengio formalized this using the spectral (largest singular value) of the Jacobian. When for all , the product shrinks exponentially. When , it grows exponentially. The boundary is unstable — any small perturbation pushes you to one side or the other.
The fundamental dilemma: memory vs. learnability
The deepest insight of the paper is not just that gradients vanish — it's that vanishing gradients and reliable are two sides of the same coin.
For an RNN to "remember" information, its hidden state must settle into a stable region — a basin of attraction (or hyperbolic attractor) where small perturbations don't knock the state out. Mathematically, this requires the eigenvalues of the Jacobian at the attractor to be less than 1 in absolute value. But this is exactly the condition that makes gradients vanish!
The paper frames it as a trade-off: if you want robust information storage (eigenvalues well below 1), then gradients decay exponentially and the network can't learn to use that memory. If you want strong gradients (eigenvalues near or above 1), the stored information becomes fragile — or new inputs can easily overwrite it.
This is like a filing cabinet with a stiff lock: the lock keeps documents safe from being accidentally knocked out (robust storage), but the same stiffness makes it hard to open the cabinet to file or retrieve anything (learning). A loose lock makes filing easy but documents fall out at the slightest bump.
Why sigmoid and tanh make it worse
The plays a critical role. The sigmoid function has a maximum of 0.25 (at ). For tanh, the maximum is 1.0 (also at ). This means:
-
With sigmoid: each Jacobian factor is bounded by . Even if , the factor is at most 1.0 — and in practice, activations are rarely at , so the actual bound is much lower. Gradients almost always vanish.
-
With tanh: the bound is , which gives slightly more room but still suffers the same exponential behavior.
The flat tails of these saturating functions act as gradient killers: once a enters the saturated region (), the local derivative drops to near zero, and no gradient can pass through.
Experimental evidence: the latch task
Bengio et al. designed a diagnostic task to expose the problem cleanly. The "latch task" works like this: early in a sequence, the network sees a binary signal (0 or 1). Then it processes many irrelevant "distractor" time steps. At the end, the network must output the value of that early signal.
With a time lag of 20 steps, standard BPTT succeeded. With a lag of 50 steps, it failed completely — the gradient had decayed so much that the network couldn't learn to connect the early input to the late output. The network behaved as if the early signal never existed.
This clean failure confirmed the theoretical prediction: the problem isn't just about "not enough training time" — it's a mathematical impossibility for vanilla gradient descent to learn these dependencies beyond a certain lag.
Proposed alternatives and their legacy
Bengio et al. didn't just diagnose the problem — they also proposed solutions, though the most impactful ones came from researchers inspired by this analysis:
In the paper itself, the authors explored: (1) simulated annealing as a non-gradient optimization method that avoids the vanishing gradient entirely; (2) discrete error propagation using sign changes rather than continuous gradients; and (3) time-weighted penalties that give more learning signal to recent time steps. These worked on toy problems but didn't scale.
Inspired by this analysis, other researchers developed the solutions we still use today:
-
LSTM (1997): Hochreiter & Schmidhuber introduced gated memory cells with a "constant error carousel" — a path where the gradient flows unchanged (eigenvalue = 1 along the ), bypassing the vanishing gradient entirely.
-
Gradient clipping (2013): Pascanu et al. showed that while vanishing gradients are structural, exploding gradients can be handled by simply capping the gradient norm. This was a direct extension of Bengio's analysis.
-
Xavier/Glorot initialization (2010): Glorot & Bengio (yes, the same Bengio) showed that initializing weights so each preserves the of activations delays the onset of vanishing/exploding gradients in deep feedforward networks.
The same idea in code
Simplified to show the idea — not the real implementation.
import numpy as np
def sigmoid(z):
return 1 / (1 + np.exp(-z))
def sigmoid_derivative(z):
s = sigmoid(z)
return s * (1 - s) # max value: 0.25 at z = 0
def compute_gradient_product(W_h, T, seed=42):
"""Compute the product of T Jacobian matrices for a simple RNN.
Returns the norm of the gradient reaching step 0 from step T.
This is what BPTT must propagate — if it vanishes, learning stops.
"""
rng = np.random.RandomState(seed)
d = W_h.shape[0]
grad = np.eye(d) # start with identity
for t in range(T):
z_t = rng.randn(d) * 0.5 # simulated pre-activation
D_t = np.diag(sigmoid_derivative(z_t)) # diagonal Jacobian of f
J_t = D_t @ W_h.T # one step's Jacobian
grad = grad @ J_t # accumulate product
return np.linalg.norm(grad)
# --- Experiment ---
d = 10
for scale in [0.5, 1.0, 2.0]:
W = np.random.randn(d, d) * scale / np.sqrt(d)
norms = [compute_gradient_product(W, T) for T in [10, 50, 100]]
print(f"scale={scale:.1f} T=10: {norms[0]:.6f} "
f"T=50: {norms[1]:.6f} T=100: {norms[2]:.6f}")
# Typical output:
# scale=0.5 T=10: 0.000012 T=50: ~0.0 T=100: ~0.0 (vanishing)
# scale=1.0 T=10: 0.003 T=50: ~0.0 T=100: ~0.0 (still vanishes!)
# scale=2.0 T=10: 587.3 T=50: 1e+18 T=100: inf (exploding)Understanding attractors: how RNNs store (and lose) information
A central concept in the paper is the "hyperbolic attractor" — a fixed point or region in the hidden state space where the dynamics naturally pull the state toward. Think of it as a valley in a landscape: a ball placed anywhere on the hillside will roll down to the valley floor and stay there.
When an RNN stores a bit of information (say, "the input was category A"), it does so by settling into a specific attractor basin. The depth of the valley determines robustness: a deep valley means the state won't be knocked out by noise, but also means gradients can't escape the valley to send learning signals backward through time.
The paper's key figure shows this visually: in the basin of attraction, all trajectories converge to the attractor (good for storage), but the Jacobian eigenvalues are less than 1 everywhere in that basin (bad for gradients).
Why it mattered
1991
Hochreiter's thesis
First formal analysis of the vanishing gradient problem in RNNs, showing gradient exponential decay through time steps.
1994
This paper (Bengio et al.)
Proved the vanishing/exploding gradient dilemma mathematically and revealed the fundamental trade-off between memory stability and gradient flow.
1997
LSTM
Hochreiter & Schmidhuber's solution: gated cells with a constant error carousel that maintains gradient flow with eigenvalue = 1.
2010
Xavier/Glorot initialization
Glorot & Bengio showed how to initialize weights to preserve activation variance across layers, delaying gradient degradation.
2013
Gradient clipping
Pascanu et al. extended Bengio's analysis and proposed clipping the gradient norm to handle the exploding side of the problem.
2014
GRU
Cho et al. simplified LSTM's gating into two gates, still solving the vanishing gradient with a similar constant-flow mechanism.
2015
Residual connections (ResNet)
He et al. applied the same principle to feedforward networks: skip connections create a gradient highway that bypasses vanishing gradients across depth.
2017
Transformer
Vaswani et al. replaced recurrence entirely with self-attention, reducing the path between any two positions to one step — the ultimate solution to the temporal vanishing gradient.
CitationBengio, Simard, Frasconi. Learning Long-Term Dependencies with Gradient Descent is Difficult. IEEE Transactions on Neural Networks, 1994.
Terms in this paper
- Vanishing Gradientاضمحلال متجهات الميل
- Exploding Gradientانفجار التدرج التفاضلي
- Recurrent Neural Network (RNN)الشبكة العصبية التكرارية
- Long-Term Dependencyالاعتمادية البعيدة المدى
- Jacobianمصفوفة جاكوبي
- Eigenvalueالقيمة الذاتية
- Backpropagationالتحديث التراجعي
- Credit Assignmentإسناد الائتمان
- Gradient Clippingتقليم التدرجات الحسابية
- LSTMشبكة الذاكرة الطويلة قصيرة المدى
- Xavier Initializationتهيئة Xavier