VisualAI
Chapter 2 · How Machines Learn

Patterns & Prediction

Learning is just nudging a guess to be a little less wrong, over and over.

8 minLesson 3 of 23

Here's the secret at the heart of machine learning, and it's almost insultingly simple: make a guess, measure how wrong it is, nudge the guess to be a little less wrong. Repeat forever.

Suppose every dot below is a house: how far along the street it sits (left to right) versus its price (bottom to top). We want a model that predicts price from position — a straight line through the cloud of dots. The line is our prediction; the dots are the truth.

Fit the Line

Drag the sliders, then press Train

y = 0.20·x + 5.00

Drag the teal dots to change the data · click empty space to add one · the purple line is the model's guess

Error (loss)2.92
Points9

Error over time

Slope (w)0.20
Intercept (b)5.00
Learning rate0.010
The red sticks are the model's mistakes. Learning is just the slow shrinking of those sticks.
Try this

First, fit the line by hand: drag the slope and intercept sliders to make the red sticks as short as you can. Watch the error number. Then wipe your effort with Reset the line and press Train — and watch the machine do the same thing automatically, the error graph sliding downhill.

Measuring “wrongness”

Each red stick is the gap between a real dot and the line's guess for it — a single mistake. Add up all those mistakes (squared, so big misses hurt more) and you get one number that scores the whole line. That number is the loss. Low loss means a good fit. The entire goal of training is to make the loss as small as possible.

Rolling downhill

So how does Train find the bottom? Imagine the loss as a valley and the model standing somewhere on its slope. At each step it feels which way is downhill and takes a small step that way. Do that again and again and you roll to the bottom — the lowest-error line. This is gradient descent, and it is the engine inside essentially every modern AI.

Key idea

Learning = repeatedly nudging the model to lower its loss. The size of each nudge is the learning rate. Crank it too high and watch the line thrash around and fly off — too big a step overshoots the valley. Too low and it crawls. Finding that balance is a real part of the job.

The payoff

A straight line only has two knobs to tune — slope and intercept. The astonishing thing is that ChatGPT learns in the exact same way: guess, measure loss, nudge, repeat. It just has hundreds of billions of knobs instead of two. To get there, we need a knob-holder more flexible than a line. Meet the neuron.