DAILY PRACTICEBuild your AI engineering skills, one problem at a time.Try today's challenge
InferenceAIStart learning path

Mathematics & Statistics · Intermediate

Gradient descent

Understand gradient descent through practical AI engineering decisions, measurable examples, and interview-ready explanations.

INTERACTIVE ENGINEERING · TEACHING MODEL

Gradient descent

Follow a parameter down a loss curve and see why step size matters.

0L(w) = w²w
Parameter w3.0000
Loss w²9.0000

The dashed path connects successive updates. Follow the filled point.

Change the experiment

Core calculation
loss = w ** 2
gradient = 2 * w
w = w - learning_rate * gradient
Try it yourself

Compare learning rates 0.1, 0.5 and 1.1. Which converges fastest, and which diverges?

Update 0: w = 3.0000, loss = 9.0000.

For this quadratic, convergence requires 0 < learning rate < 1. Real training losses have different curvature.

Playback pauses in hidden tabs and offscreen. With reduced motion enabled, use the timeline or Next step.

What the update means

Gradient descent adjusts model parameters in the direction that reduces a differentiable loss locally. For a parameter w, learning rate η, and loss L, the update is w ← w − η ∂L/∂w.

Why the learning rate matters

A small step can make progress slowly. A large step can overshoot the minimum, oscillate, or diverge. In the example above, a learning rate above 1 increases the magnitude of w after each step.

When you train a real model

Parameters are vectors rather than a single number, and gradients are often estimated on mini-batches. Monitor training and validation metrics, and investigate data and numerical issues when loss behaves unexpectedly.

Explore a model architecture →

Related concepts

Linear algebra intuition →

Probability for models →

Statistical inference →