Kolton Ndoj

Gradient descent: what 'learning' actually means

Every time an AI gets trained: voice assistants, photo search, chatbots, translation

What problem does it solve?

How can a computer tune millions of knobs to make its mistakes as small as possible?

The big idea

Picture the total error as a landscape of hills and valleys, where every position is a setting of the knobs. You're blindfolded on it, but you can feel which way the ground slopes under your feet. Take a step downhill, feel again, step again. That's all 'learning' is: measure the error, compute the slope (the gradient), nudge every knob a little in the downhill direction, and repeat millions of times. The step size matters: too small and you crawl, too big and you leap across the valley.

How it works, step by step

  1. 1. Start with random knob settings w.
  2. 2. Measure the error (the 'loss') on some examples.
  3. 3. Compute the gradient: how the loss changes as each knob is nudged.
  4. 4. Move every knob a small step against the gradient: w ← w − η·∇L.
  5. 5. Repeat until the loss stops dropping.

The key formula

w←w−η ∇L(w)w \leftarrow w - \eta\,\nabla L(w)
ww
all the knobs (the 'weights'); big AI models have billions
L(w)L(w)
the loss: one number measuring how wrong the model is
∇L\nabla L
the gradient: the direction of steepest uphill, so we go the opposite way
η\eta
the learning rate: how big a step to take

How fast is it?

Each step needs the gradient, which backpropagation computes for about the cost of running the model a couple of times. Real training uses 'stochastic' gradient descent: estimate the slope from a small random batch of examples instead of all of them, which is noisy but much faster. Improved versions like Adam adjust the step size per knob.

Graph for Gradient descent: what 'learning' actually means -378-2
A 1D loss landscape. With a = 0 it's a smooth bowl and going downhill always finds the bottom; add bumps and a ball rolling downhill can get stuck in a small dip (a local minimum). (drawn with the default slider values — move the sliders live)

Try it yourself

Fun fact

The method is over 175 years old: Augustin-Louis Cauchy described it in 1847, for calculating the orbits of celestial bodies. The newest AI runs on a 19th-century idea plus enormous computing power.

Related

Play with the live demo →

AI · Intermediate