AI literacy · What AI actually is · Lesson 2 of 4
How machines learn
Patterns in data, training and testing.
11 minute read
Machine learning sounds mysterious, but the core idea fits in one sentence: instead of telling a computer the rules, you show it examples and let it work the rules out. Everything else, from spam filters to chatbots, is that sentence scaled up.
Learning by example
Suppose you want a system that spots whether a photo contains a cat. Nobody can write rules for that. Pointy ears? So do foxes. Whiskers? So do rats. Instead, you gather many thousands of photos labelled cat or not cat and feed them to a model, which starts out making random guesses. Each time it guesses wrong, its internal settings are nudged in the direction that would have made the guess better. Repeat millions of times and the model ends up encoding patterns no human ever wrote down. That process is called training.
It is worth slowing down on the phrase its internal settings are nudged, because that is where the learning actually happens. A model is really a huge pile of numbers, often called parameters or weights, and those numbers control how it turns an input into a guess. At the start they are random, so the guesses are random. After each guess the system measures how wrong it was, then adjusts every number a tiny amount in the direction that would have made the guess a little less wrong. No single adjustment teaches the model anything. But repeat the measure and adjust step across millions of examples and the numbers settle into a configuration that encodes real patterns, the same way a river with no plan still carves a sensible path downhill one small movement at a time.
Training data and test data
Here is the part people miss. If you test the model on the same photos it trained on, a great score proves nothing. The model may have simply memorised those exact photos, the way you can memorise the answers to last year's exam without understanding the subject. So the data is split: a training set the model learns from, and a test set it never sees until the end. Performance on the test set is the real measure, because it shows whether the model learned patterns that generalise to new examples.
Put rough numbers on it. Say you gather 10,000 labelled photos and hold back 2,000 of them as the test set, training only on the other 8,000. After training, the model scores 96 out of 100 on photos from the training set, which sounds excellent. Then you run the 2,000 held back photos and it scores 78. That gap between 96 and 78 is the number that matters, because the held back photos are the only ones that behave like the real world the model will meet after it ships. A model that scored 96 on both would be genuinely better than one that scored 99 on training and 70 on test, even though 99 looks bigger, and learning to trust the test number over the training number is most of what separates careful machine learning from wishful thinking.
Overfitting: memorising instead of learning
A model that scores brilliantly on its training data and poorly on new data has overfitted. It has latched onto details that were accidents of the training set rather than real patterns. If most cat photos in the training set happened to be taken indoors, an overfitted model may quietly learn indoors means cat, then fail on the first cat it meets on a lawn. Overfitting is the machine version of a student who can recite the textbook but cannot answer a question phrased differently.
Why data quality decides everything
A model can only learn patterns that exist in its data. More data usually helps, because rare situations get covered. But better data matters even more. If the examples are mislabelled, the model learns the mistakes. If the examples leave out whole groups of people or situations, the model fails on exactly those. A pattern finding machine fed a skewed picture of the world will faithfully learn a skewed picture of the world. Later lessons on bias build directly on this point.
Learning is not understanding
It is tempting to picture the model understanding cats the way you do, building up an idea of what a cat is. That is not what happens, and the difference matters. The model never forms a concept of cat. It finds statistical patterns that reliably separate the photos labelled cat from the ones labelled not cat, and those patterns can be shallow in ways that would never fool a person. Show it a photo where the lighting, the angle and the background all match its training cats but the animal is actually a small dog, and it may cheerfully answer cat, because it was matching the wrapping rather than the thing inside. Keep that picture in mind whenever a model impresses you: it has found patterns that work, which is not the same as knowing what it is looking at.
This is already running your week
You have been living inside trained models for years without calling them that. The spam folder in your email is a model trained on billions of messages people marked as junk. The order of videos in your feed is a model trained on which clips people like you watched to the end. Autocorrect, face unlock, the suggested replies in your messages, the fraud check that pauses a strange looking tap of your bank card, all of them are pattern finders trained on examples rather than programs following handwritten rules. Once you can see them, you also understand their failures: autocorrect mangles a word it was never trained on, and your feed keeps showing you one topic because that is the pattern your watching taught it, not because anyone decided you should see it.
Everything here sets up the two lessons on either side of it. A chatbot is a machine learning model at enormous scale, so the next lesson on what a language model really does is this same story of patterns in data with the volume turned all the way up. And because a pattern finder faithfully learns whatever its data contains, including the skews and gaps in that data, the later lessons on bias and fairness start exactly where this one ends, with the question of what was in the examples.
Check your understanding
8 questions. Pick an answer for each, then check.
1. The core idea of machine learning is
2. Why is a model tested on data it never saw during training?
3. A model scores 99% on its training data and 60% on new data. This is a classic sign of
4. Most cat photos in a training set were taken indoors. The trained model may
5. According to the lesson, when a model behaves strangely the first question to ask is
6. During training, what actually changes inside the model?
7. A model scores 96 on its training photos and 78 on held back test photos. Which number better predicts how it will do in the real world?
8. When a model labels a photo cat, it has