Understanding AI · lesson 18 of 60 · about 6 minutes
Small Adjustments
Once a model knows how wrong it is, it nudges its numbers to be a little less wrong. See how.
What you'll learn
- Explain that training changes a model's numbers
- Decide which way to nudge a number to shrink the error
- Follow one adjustment step
The numbers inside a model
A model is mostly numbers. A line has a slope; a big AI model has billions of numbers, called weights. Training means changing those numbers.
The trick: try nudging a number up a little. If the error shrinks, keep going that way. If it grows, go the other way.
A model price = w x size, guessing the price of a 10 square metre room that costs 50. Its weight w starts at 3.
size = 10
price = 50
def error(w):
return abs(w * size - price)
w = 3
print(error(w))
print(error(w + 1))
print(error(w - 1))Output
20
10
30Feel your way downhill
Picture the error as a hill and the model standing somewhere on it in the fog. It can't see the bottom, but it can feel which way is downhill, and take a small step that way. Real AI does this with maths that works out the downhill direction for every weight at once.
Tip
Going up from 3 to 4 cut the error from 20 to 10. So the model should nudge w upwards.
Now try it yourself
This lesson is free in Codiqo, with 6 questions on what you just read. You can only learn to code by writing code, so it ends with a short program you write yourself, which we run and check straight away.