Skip to the page
HOW MACHINES LEARN
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9

Page 1 of 9

Learning is turning a knob until the miss gets small

Start with the smallest machine there is. It has one input, one number you can adjust, and one answer.

Turn the weight and watch the error. The curve is the error for every possible setting of the weight. Press Rock it to find the downhill direction by experiment. Then press Calculate the slope and get the same answer with one multiplication.

A machine with one number in it

A machine, on these pages, is arithmetic with numbers in it that can be changed. The numbers that can be changed are called weights. This first machine has one weight, and all it does is multiply.

prediction = weight × input

whatever goes in is multiplied by the weight, and that is the machine's answer.

Give it one example to learn from. The input is 2, and the right answer, called the target, is 1. The weight starts at 0.25, so the machine says 0.25 × 2 = 0.50. It is low by half.

One number for how wrong

To improve, the machine needs a single number that says how wrong it is. Take the miss, which is the prediction minus the target, and square it. Squaring makes a miss count the same whether it is high or low, and makes a large miss count much more than a small one. The half in front tidies the next step and changes nothing else.

miss  = prediction − target      0.50 − 1  = −0.50
error = ½ × miss²                ½ × 0.25  =  0.125

the machine is half a unit low, and its error is one eighth.

Two ways to find which way to turn

The first way is to try it. Turn the weight down a little, then up a little, and see which way the error falls. Bernard Widrow trained his first adaptive systems this way in 1957 and 1958, in computer simulations. He later described it as rocking each weight back and forth.

The second way is to calculate what the rocking would show. The weight multiplies the input, so if the weight goes up by a small amount, the prediction goes up by that amount times the input. That gives the rate at which the error changes, called the slope.

slope = miss × input             −0.50 × 2 = −1.00

near this setting, the error falls by 1 for every unit the weight rises.

Why the slope is miss × input, one step at a time
  1. Raise the weight by a small amount. Call the amount d.
  2. The prediction rises by d × input, because the input is what the weight multiplies. So the miss rises by d × input too.
  3. When a number changes a little, half its square changes by the number times that little change. Half of 3² is 4.5. Half of 3.01² is 4.53. The change, 0.03, is 3 × 0.01.
  4. So the error rises by miss × (d × input).
  5. Per unit of weight, that is miss × input.

The slope carries two messages. Its sign says which way to turn: a negative slope means that raising the weight lowers the error. Its size says how much this weight matters right now.

Both of its factors make sense by themselves. If the miss is zero, nothing should change. If the input was zero, this weight had no part in the answer, and it gets no correction.

Take a step

Move the weight against the slope, by a fraction of it. The fraction is called the step size.

new weight = weight − step size × slope
           = 0.25 − 0.1 × (−1.00)  =  0.35

prediction = 0.35 × 2 = 0.70        error = ½ × (−0.30)² = 0.045

one step took the error from 0.125 to 0.045.

Do it again and the error falls again. Each step is smaller than the one before, because the slope shrinks as the miss shrinks. Press Run to the bottom above to watch it settle.

That is all learning means on these pages. Measure the miss, find each weight's slope, step downhill, repeat. Every later page is about keeping that recipe working as the machine grows.

Who thought of this

CARRY THIS FORWARD

A machine can learn by small steps if every adjustable number has a slope: an answer to which way, and how fast.