Exercises — Vanishing and exploding gradients
Prerequisites you may want open: Backpropagation, Activation Functions, Weight Initialization, Batch Normalization, Residual Networks (ResNet), LSTM and GRU, Gradient Descent.

The picture above is the whole story: on the horizontal axis, and the gradient size on the vertical axis (log scale). Left of the dashed line () the curve dives to the floor — vanishing. Right of it () it rockets up — exploding. Only right at does the signal survive.
Level 1 — Recognition
Exercise 1.1
State, in one sentence each, what "vanishing" and "exploding" gradient mean in terms of the product .
Recall Solution
- Vanishing: , so as depth grows — the early-layer gradient shrinks toward zero and those layers stop updating.
- Exploding: , so — the early-layer gradient blows up, weight updates become huge, and the loss can go to NaN. WHAT it looks like: on the s01 figure, vanishing is the curve hugging the floor on the left; exploding is the curve shooting off the top on the right.
Exercise 1.2
The sigmoid derivative has a maximum value. What is it, and at what input does it occur?
Recall Solution
. This is a downward parabola in the variable , maximized when . That gives , occurring at (because ).
Exercise 1.3
For an -layer network, how many multiplicative Jacobian factors appear in the gradient of the loss w.r.t. the first layer? Why that count?
Recall Solution
factors. Going from the last layer back to layer crosses layer-to-layer links, and each link inserts exactly one factor . Hence the bound .
Level 2 — Application
Exercise 2.1
A network uses sigmoid activations, , and . It has layers. Compute the shrink factor for the first layer's gradient.
Recall Solution
. With links: The first layer receives a gradient roughly four million times smaller than the last — effectively frozen.
Exercise 2.2
The weights are too large: , depth . Compute and state what happens to training.
Recall Solution
, so . The gradient is amplified ~3300× through the stack. Updates overshoot, weights swing wildly, and loss typically diverges to NaN. Fix: smaller init or gradient clipping.
Exercise 2.3
He initialization sets with a hidden width . What is the standard deviation each weight is drawn with?
Recall Solution
. Standard deviation: So each weight is drawn from a distribution with std . The compensates for ReLU zeroing about half the activations (see Weight Initialization).
Level 3 — Analysis
Exercise 3.1
You measure the gradient norm at layer 1 as and at layer 30 as . Assuming a constant per-layer gain , estimate . (There are links.)
Recall Solution
The ratio of norms is . Take logs: , so A per-layer gain of about — well below — fully explains the six-order-of-magnitude collapse.
Exercise 3.2
A student proposes: "Compensate for a sigmoid net by choosing , forcing ." Analyze whether this works and what side effect appears.
Recall Solution
Arithmetically — the maximum-slope case is balanced. But only holds at . Large weights push pre-activations to big magnitudes, where (saturation), so the actual per-neuron slope collapses far below . Net effect: still drops below 1 for most neurons, and you have added saturation. Inflating to fix vanishing sigmoids trades one failure for another; the real fix is normalization or a non-saturating activation.
Exercise 3.3
Given a residual layer , write the Jacobian and explain why this rescues the gradient.
Recall Solution
The identity guarantees a "gain-1 path": even if has tiny norm, the product across layers still contains , so the gradient cannot vanish to zero along that path. This is exactly why ResNets train at 50+ layers.
Level 4 — Synthesis
Exercise 4.1
You must train a 40-layer feed-forward classifier. Design a configuration (activation + init) that keeps , and justify each choice against the gain formula.
Recall Solution
Choice: ReLU activations + He initialization + optional Batch Norm.
- ReLU gives (slope 1 for positives), so the activation factor is , not — removes the sigmoid's built-in shrink.
- He init sets so that contributes a factor after ReLU has zeroed half the units; the restores the halved variance. Net .
- Then : depth stops mattering for signal size.
- Batch Norm keeps centered so ReLU units don't collectively die, protecting the realized slope.
Exercise 4.2
A recurrent net unrolled over time steps has a per-step recurrent gain . Compute the gradient shrink over the full unroll, and name the architectural fix designed for exactly this.
Recall Solution
Unrolling 100 steps gives links (or ; the exponential is the point): The gradient shrinks by ~ across time — early time steps learn almost nothing. Fix: LSTM/GRU gates, whose additive cell-state update gives a near- recurrence (an -like path through time), just like residual connections do through depth.
Exercise 4.3
Explain, using the gain formula, why gradient clipping is a fix for exploding but does nothing for vanishing.
Recall Solution
Clipping rescales only when — it caps large gradients. Exploding means produced a huge norm, which clipping tames. Vanishing produces a tiny norm (), never exceeding the threshold, so clipping never triggers; worse, it cannot manufacture signal that has already collapsed to . Vanishing needs structural fixes (init/activation/skip), not post-hoc rescaling.
Level 5 — Mastery
Exercise 5.1
A 50-layer net trains fine on the last 10 layers but the loss plateaus high. Per-layer gradient norms measured: layer 50 , layer 40 , layer 30 , layer 20 , layer 10 . (a) Estimate the average per-link gain from layer 50 to layer 10. (b) Diagnose the problem. (c) Prescribe two fixes in priority order and justify.
Recall Solution
(a) From layer 50 to layer 10 is links. Norm ratio . A per-link gain — consistently below 1. (Sanity check: predicts layer 40 ✓; ✓.) (b) Classic vanishing gradient: later layers learn (near-1 gradients), early layers are near-frozen (), so the loss plateaus high — this is the parent note's "high loss can coexist with vanishing gradients." (c) Priority fixes: (1) add residual/skip connections — the path forces per-link gain regardless of depth (biggest structural lever for 50 layers). (2) add Batch Normalization to keep activations in the healthy-slope region so realized rises toward 1. (Re-init to He would also help if not already done.)
Exercise 5.2 (capstone)
Prove the bound from the recurrence , stating precisely which two inequalities you use.
Recall Solution
Write each backward link as a linear map , so . Unrolling from to : Take the norm and use (i) sub-multiplicativity of the operator norm, : Then use (ii) the uniform per-link bound for every link. There are exactly links, so: The two inequalities are: (i) norm of a product product of norms, and (ii) each factor's norm . See Backpropagation for the recurrence itself.