Gradient descent, from intuition to update rule
Sunil Tiwari · Oct 12, 2026 · 2 min read
Why stepping against the gradient works, how the learning rate changes everything, and a 10-line implementation.
Gradient descent is how almost every model learns. You stand somewhere on a loss surface and repeatedly take a step downhill. The canvas sketches the loop; the note derives the rule.
The setup
We have parameters and a loss that measures how wrong the model is. We want:
Why the negative gradient?
A first-order Taylor expansion around for a small step :
Among all steps of a fixed length, is most negative when points exactly opposite the gradient. That gives the update rule:
Here is the learning rate, the size of each step.
A worked example
Take , so . Start at with :
The learning rate decides everything
- : halves the distance every step. Smooth convergence.
- : . Bounces between 4 and −4 forever.
- : every step overshoots further. Diverges.
For this loss, convergence needs . In general the bound depends on the curvature: of the Hessian.
The training loop
flowchart LR
A[Initialise θ] --> B[Compute loss L θ]
B --> C[Compute gradient ∇L]
C --> D[θ ← θ − η∇L]
D --> E{Converged?}
E -- no --> B
E -- yes --> F[Done]Ten lines of code
def gradient_descent(grad, theta, lr=0.1, steps=100, tol=1e-8):
for _ in range(steps):
step = lr * grad(theta)
theta = theta - step
if abs(step) < tol:
break
return theta
gradient_descent(lambda t: 2 * t, theta=4.0, lr=0.25) # → ~0.0