3.2.14 · D1Training Deep Networks

Foundations — Gradient clipping

2,067 words9 min readBack to topic

This page assumes nothing. Before you can read the parent note Gradient Clipping, you need to be fluent with about a dozen little symbols. We build each one from a picture, in an order where every new idea only uses the ones before it.


0. The picture the whole topic lives in

Everything in this topic happens on a loss landscape: a surface where the height tells you how wrong the network currently is. Low = good, high = bad. Training = walking downhill.

Figure — Gradient clipping

1. Numbers, then a list of numbers: the vector

Picture: a vector is an arrow. Start at the origin ; the numbers tell you how far to go right and up. So means "3 right, 4 up", and the arrow points to that spot.

Why the topic needs it: the gradient is a vector — one number per adjustable knob (parameter) in the network. A tiny network might have 2 knobs; a real one has millions. But the ideas work identically, so we practice with 2- and 3-number vectors you can draw.

We write a vector's individual numbers using a subscript (a small index): if , then is the first number and the second. The subscript is just a name tag, nothing more.


2. How long is an arrow? The norm

The single most important quantity in this whole topic is: how long is the gradient arrow? A short arrow = small safe step. A giant arrow = dangerous leap.

Why this exact formula and not something else? We want ordinary ruler distance, and ruler distance in a right triangle is the Pythagorean theorem: the diagonal is the square root of the sum of the squares of the sides. That is the reason the square-root-of-squares shows up.

Figure — Gradient clipping

3. Scaling an arrow: multiply a vector by a scalar

Picture: the arrow keeps pointing the same way but its length changes. makes it half as long; makes it twice as long. If the direction is untouched — this is the whole secret of clip-by-norm: it multiplies the gradient by one positive scalar, so the arrow's direction survives and only its length shrinks.

The key fact we will use: because scaling multiplies length by , Double the arrow, double its length. This is why choosing later makes the new length exactly .


4. Two comparison tools: and

The parent formula is . Two mini-functions live in there.

Why it appears: we want to shrink an oversized arrow but never stretch a safe one. Taking the minimum with guarantees the scale factor is at most (never enlarges) — one formula handles "already safe" and "too big" at once.

Picture: imagine two fences at heights and . Any value poking past a fence gets pushed back to it. This is clip-by-value — it treats each number separately, which (as the parent warns) can bend the arrow's direction.

The hat notation (little "^" over the letter) just means "the modified after clipping". It's a fresh name for the output, not a new operation.


5. Where the gradient comes from: derivative and

Picture: stand on the loss surface and tilt your head along one knob's direction. The steepness you feel is the derivative. Steep downhill = big negative slope; flat = zero slope.

Why the topic needs it: the gradient is literally the collection of these slopes, one per knob. That is what tells us which way is downhill and how steep.

So the gradient we clip is exactly this steepness-vector. When it's short, all slopes are mild. When it's enormous (near a cliff), the length is untrustworthy but the direction still roughly points uphill — which is why we keep direction and trim length.


6. The update rule and its symbols:

Picture: you're the dot on the surface. is the downhill arrow; scales it to a comfortable stride; you move there. Repeat.


7. Why gradients explode: the product of many factors

Why the topic needs it: a deep network passes signals through many layers, and backpropagation multiplies one factor per layer. If each factor is a bit bigger than , the product grows like — explosively with depth. That geometric blow-up is why gradients explode. (The parent note calls each factor a "Jacobian singular value"; for D1 you only need: many numbers bigger than 1, multiplied together, get huge fast.)

Figure — Gradient clipping

8. Putting the symbols together (preview of the parent)

You can now read the boxed formula fully:

  • — the gradient vector (§1).
  • — its length via Pythagoras (§2).
  • — a chosen threshold (the maximum allowed length).
  • — the scalar that would shrink the length to exactly (§3, since ).
  • — "shrink if too big, else leave alone" (§4).
  • — the safe, trimmed gradient handed to the update rule (§6).

Every piece is now earned. Head to the parent note for the full derivation and worked cases.


Prerequisite map

scalar - one number

vector - list of numbers = arrow

norm - length via Pythagoras

scalar times vector - scale an arrow

scale factor c over norm

min and clip functions

Gradient Clipping

derivative - slope

gradient - vector of slopes

update rule w minus eta g

product of many factors

exploding gradient


Equipment checklist

Cover the right side and test yourself — you're ready for the parent note when all pass.

What is a vector, in one phrase?
An ordered list of numbers, drawn as an arrow from the origin.
How do you compute the norm of ?
— Pythagoras, straight-line length.
What happens to an arrow when you multiply it by a positive scalar ?
Its direction stays the same; its length is multiplied by .
Why is useful here?
It lets us pick so the new length is exactly .
What does do and why is it in the clip formula?
Returns the smaller value; it shrinks oversized gradients but never enlarges safe ones.
What does do?
Forces into using fences at (clip-by-value).
What is a gradient in plain words?
The vector of slopes (one per knob) pointing toward steepest loss increase.
What do and mean in ?
"Gets replaced by"; is the small positive learning rate (step size).
Why does the step length cause the cliff problem?
If explodes, the stride becomes huge and overshoots the valley.
Why do gradients explode with depth?
Backprop multiplies one factor per layer; factors above 1 multiply to a geometric blow-up like .

Connections