This Machine Learning concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.
Machine Learning
RNNs and Vanishing/Exploding Gradients
Unroll an RNN and watch the backward signal cross repeated Jacobians, shrinking, persisting, or exploding as each step's multiplier sits below, near, or above one.
Concept Structure
RNNs and Vanishing/Exploding Gradients
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learner Contract
What this page should let you do.
2 prerequisites listed; refresh them before leaning on the math or code.
Explain the mechanism, trace the main notation, and test one prediction in the live demo.
Read the intuition before the notation; the math should name a mechanism you already felt.
Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.
Claim/source review status
Substantive review recorded
1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
You are here because sequence models do something ordinary feedforward networks do not: they reuse the same state update again and again.
Before this, know backpropagation and activation derivatives. By the end, you should be able to unroll a recurrent neural network, point to the repeated Jacobian product, and predict when an early-time gradient becomes too tiny or too large to be useful.
An RNN carries a hidden state through time:
That forward arrow feels like memory. The backward pass reveals the cost of that memory. If a loss at time needs to teach something that happened near time , the gradient must walk backward through each recurrent state transition.
One step is not scary. Eight steps might be fine. Hundreds of steps can become a corridor of multiplication.
- If the local backward multipliers are usually smaller than , the early gradient fades.
- If they are usually close to and well conditioned, the signal can stay usable.
- If they are usually larger than , the signal can explode.
This is not just an RNN history lesson. It is the sequence-model version of the same chain-rule problem you saw in activation functions and initialization. LSTM/GRU gates, gradient clipping, residual/direct paths, and attention all become easier to understand once you can see the corridor.
The caveat is important: real RNNs have vector states, nonlinearities, changing inputs, time-varying Jacobians, and losses at many positions. The demo below is a finite linearized witness for the mechanism, not a verdict on every recurrent architecture.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Let the hidden state be and the input be . A basic RNN update is
where is the recurrent weight matrix, maps the input into hidden space, is a bias vector, and is an elementwise nonlinearity such as .
Suppose a scalar loss depends on the final state . Define the local recurrent Jacobian
Backpropagation through time applies the chain rule through the unrolled graph. For an earlier state ,
That product is the central object. Its norm can be bounded by
This bound is not an equality in general, because matrix directions and conditioning matter. It is still the right warning sign: repeated contraction tends to erase long-range credit assignment, while repeated expansion can make updates unstable.
For the demo, we collapse the corridor into a scalar linearized toy where each local Jacobian has the same effective multiplier :
When , shrinks as grows. When , the signal stays near its original scale. When , the signal grows. This is the smallest possible witness for the repeated-product mechanism.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import numpy as np
T = 8
presets = {
"vanish": 0.55,
"usable": 1.0,
"explode": 1.35,
}
def backward_corridor(rho, T=8, g_T=1.0, clip=None):
grad = g_T
trace = [grad]
for _ in range(T):
grad *= rho
if clip is not None:
grad = np.clip(grad, -clip, clip)
trace.append(grad)
return np.array(trace)
for name, rho in presets.items():
trace = backward_corridor(rho, T)
print(name, "rho^T =", round(rho**T, 4),
"g0 =", round(trace[-1], 4))
This code intentionally uses a scalar linearized corridor. In a real RNN, each step multiplies by a matrix , and changes with the hidden state, input, activation derivative, and parameters. The scalar version isolates the one thing that must not be missed: long-range gradients are products, not single slopes.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Use the RNN Gradient Corridor to inspect an unrolled sequence from to . The forward hidden states are visible, but the backward gradient trace is locked until you commit.
Before reveal, choose what happens to the target gradient :
- Vanishes: repeated contraction pushes the gradient toward zero.
- Stays usable: the effective multiplier stays near one.
- Explodes: repeated expansion makes the gradient too large.
After reveal, compare the effective multiplier , the backward norm trace, and the caveat strip. This is not a verdict on every recurrent architecture; it is a finite corridor witness for repeated Jacobian products. If the path explodes, gradient clipping can bound the update norm, but clipping does not magically create long-term memory. If the path vanishes, gates and attention are motivated because they create better routes for information and gradients.
Live Concept Demo
Explore RNNs and Vanishing/Exploding Gradients
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what RNNs and Vanishing/Exploding Gradients should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
Unroll an RNN and watch the backward signal cross repeated Jacobians, shrinking, persisting, or exploding as each step's multiplier sits below, near, or above one.
Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change RNNs and Vanishing/Exploding Gradients should make visible.
Visual Inquiry
Make the image answer a mathematical question
Unroll an RNN and watch the backward signal cross repeated Jacobians, shrinking, persisting, or exploding as each step's multiplier sits below, near, or above one.
Which visible object should carry the first intuition?
Pick the cue that should make RNNs and Vanishing/Exploding Gradients easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Derives BPTT by unrolling an RNN and exposes the repeated product of recurrent derivatives/Jacobians.
Open sourceGrounds the RNN hidden-state recurrence and language-model setting.
Open sourceCourse notes for RNN language models, GRU/LSTM motivation, and the difficulty of accessing information many steps back.
Open sourcePrimary analysis source for vanishing/exploding gradient problems in RNNs and gradient norm clipping as an exploding-gradient remedy.
Open sourceClassic source on why gradient-based learning struggles as temporal dependencies span longer intervals.
Open sourceClaim Review
Unroll an RNN and watch the backward signal cross repeated Jacobians, shrinking, persisting, or exploding as each step's multiplier sits below, near, or above one.
Claims without a substantive review badge still need exact source-support review.
d2l-2026-bptt, d2l-2026-rnn, cs224n-2019-rnn-notes, pascanu-2013-training-rnns, bengio-1994-long-term-dependencies
Use equations, runnable code, and demos to check whether the source support is operational.
D2L explicitly derives the recurrent product in BPTT; Pascanu et al. analyze vanishing/exploding gradients in RNNs and propose gradient norm clipping for explosions; Bengio et al. ground the long-term-dependency difficulty; CS224N frames the practical RNN language-model setting and difficulty of accessing far-back information.
Sources: Dive into Deep Learning: Backpropagation Through Time, CS224N: Language Models, RNN, GRU and LSTM, On the difficulty of training Recurrent Neural Networks, Learning long-term dependencies with gradient descent is difficultFinite scalar linearized witness only; real RNN Jacobians vary with time, input, hidden state, nonlinearity, conditioning, truncation, and parameterization.A bounded review summary is present; still check caveats and exact reference scope.Checked D2L BPTT for unrolling, chain-rule recurrence, and repeated derivative products; Pascanu/Mikolov/Bengio for vanishing/exploding RNN training difficulties and gradient norm clipping; Bengio/Simard/Frasconi for long-term dependency difficulty; and CS224N notes for the course-level RNN language-model framing. The live demo is a scalar linearized corridor, not a full nonlinear architecture benchmark. GPT Pro/Oracle publication critique remains pending.
Reviewer: codex-local-primary-source-audit; reviewed 2026-07-02Source support candidates
book 2026Dive into Deep Learning: Backpropagation Through TimeDerives BPTT by unrolling an RNN and exposes the repeated product of recurrent derivatives/Jacobians.
book 2026Dive into Deep Learning: Recurrent Neural NetworksGrounds the RNN hidden-state recurrence and language-model setting.
course-notes 2019CS224N: Language Models, RNN, GRU and LSTMCourse notes for RNN language models, GRU/LSTM motivation, and the difficulty of accessing information many steps back.
paper 2013On the difficulty of training Recurrent Neural NetworksPrimary analysis source for vanishing/exploding gradient problems in RNNs and gradient norm clipping as an exploding-gradient remedy.
Practice Loop
Try the idea before it explains itself
Unroll an RNN and watch the backward signal cross repeated Jacobians, shrinking, persisting, or exploding as each step's multiplier sits below, near, or above one.
Before touching the demo, predict one visible change that should happen in RNNs and Vanishing/Exploding Gradients.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to a claim, equation, code, or demo
Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.Open the draft below to save one note and next action in this browser.
RNNs and Vanishing/Exploding Gradients
What is the smallest example that makes RNNs and Vanishing/Exploding Gradients click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays in this browser, attached to the selected learning item.
- References to inspect: attached references on this page.
- Definition, prerequisite, and contrast concept links
- The equation or runnable code that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - RNNs and Vanishing/Exploding Gradients Selected item key: recorded for copy. Context: Machine Learning Page anchor: recorded for copy. Open question: What is the smallest example that makes RNNs and Vanishing/Exploding Gradients click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/machine-learning/rnns-vanishing-exploding-gradients
concept:machine-learning/rnns-vanishing-exploding-gradients