AI & ML Atlas
Neural NetworkstechniqueInteractive simulation
Gradient Clipping
Caps the size of gradients so one huge step cannot wreck training.
The idea
In recurrent networks and on steep "cliffs" of the loss surface a gradient can become enormous and fling the weights far away. Clipping rescales the gradient vector to a maximum norm (or clamps each value), keeping its direction but limiting the step size.
g ← g · min(1, c / ‖g‖)
Watch it run
This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.
- current weights
- minimum
- last update
Start somewhere on the bowl. Rings are lines of equal loss; the minimum is at the centre.
- step:
- 0
- loss:
- 3.4617
1/58
Loss landscape seen from above: a long narrow valley. Final loss 0.0005.
Step by step
- 1Compute the gradient g.
- 2Measure its norm ‖g‖.
- 3If ‖g‖ exceeds the threshold c, scale g to g·c/‖g‖.
- 4Apply the optimiser update with the clipped gradient.
Where it is used
RNNs, transformers and reinforcement learning.
Watch out for
The threshold needs choosing; constant clipping hides instabilities that should be fixed.