From rules to learning
Adaeze picks up her phone and it unlocks by looking at her face. She starts typing a message to her sister, and the keyboard suggests the next word before she has thought of it. She opens a chat assistant and asks it to explain compound interest "like I'm in JSS1", and it does — in fluent, friendly sentences.
Think about everything you have learnt in this course. Every program so far was a list of instructions written by a person (Lesson 3.5, Lesson 5.1): load this, add that, if this then jump there. Now try to write the instructions for recognising Adaeze's face. What would the rules be? "If the pixel at row 400 is brown…"? Faces change with light, angle, hairstyle, glasses, a cold. Nobody has ever managed to write those rules by hand.
So how does her phone do it? Lesson 3.5 made a promise: some of the clever things computers do were found by a program that people wrote to search for patterns in huge amounts of data. This module keeps that promise. It is the last step of the journey that began with sand in Module 1: how the rock learned to recognise, predict and — in a way you will understand completely by the end — talk.
Words in this lesson
| Word | What it means |
|---|---|
| Artificial intelligence (AI) | Computer systems doing tasks that seem to need human intelligence |
| Rule-based program | A program whose every decision was written by a person |
| Machine learning | Programs that improve at a task by learning patterns from examples |
| Training data | The examples a machine-learning system learns from |
| Model | The learned numbers that capture the patterns found in training |
| Training | The process of adjusting the model's numbers using examples |
| Using a model | Running a trained model on new inputs (often called inference) |
Every program so far followed rules people wrote
Look back at Tiny's budget program (Lesson 3.5), or the Python lines in Lesson 5.1. A person decided every step: add these, compare that, if negative, jump. The computer contributed speed and obedience, nothing else.
That works brilliantly for anything you can describe precisely: payroll, bank balances, a calculator, a spreadsheet's =SUM. But try writing rules for these:
- Is this photo a cat?
- Is this voice note in Yoruba or Igbo, and what did it say?
- Is this email spam?
Take spam. A rule-based filter might say: "if the subject contains FREE MONEY, it's spam". Scammers simply write FR3E M0NEY. You add a rule; they change the spelling again. Every rule you write is a rule they can learn to avoid. For faces, voices and handwriting, it is worse: nobody even knows how to begin writing the rules, because people recognise these things without being able to say how.
A different idea: learn from examples
Here is the idea that changed computing. Instead of writing the rules, show the program examples, with the right answers, and let it find the pattern itself.
Show a spam filter ten thousand emails, each labelled "spam" or "not spam". It starts with a set of numbers that mean nothing, makes guesses, checks them against the labels, and adjusts its numbers a little each time it is wrong. After enough examples, its numbers capture patterns no person wrote down: which combinations of words, links, senders and timing tend to mean spam.
The collection of examples is the training data. The adjusting is training. The numbers it ends up with are the model.
And here is why this works at all — and why you can understand it. Every example is numbers. A photo is a grid of colour numbers (Lesson 2.4). A voice note is a list of sound samples (Lesson 2.5). An email is a list of character codes (Lesson 2.3). Machine learning is arithmetic on those numbers: lots and lots of multiplying and adding, done by the ALUs you built from gates in Module 3.
The first machines that learned
The idea is older than most people think.
A program that beat its own author. At IBM, Arthur Samuel wrote a program to play checkers (draughts). IBM explains that it improved its play over time by learning from experience, and eventually played better than Samuel himself. His 1959 paper in the IBM Journal is credited with giving the field its name: machine learning.
A machine that taught itself. In July 1958, Cornell University recounts, a research office of the US Navy presented Frank Rosenblatt's perceptron, running on a room-sized IBM 704 computer. Fed punch cards, it taught itself to tell cards marked on the left from cards marked on the right: when its guess was wrong, it adjusted itself, becoming more accurate over thousands of tries. Cornell's computer scientists describe it as the first neural network.
The perceptron had a weakness: it had only one layer, as Cornell notes. In 1969, Marvin Minsky and Seymour Papert published a book, Perceptrons, criticising it, and interest in the idea faded for years.
The staircase light that stumped the perceptron
You can see that weakness yourself, with a gate you already know: XOR, the staircase light from Lesson 3.2. Draw a square grid and mark its four corners:
- (0, 0) → light off
- (0, 1) → light on
- (1, 0) → light on
- (1, 1) → light off
A single-layer perceptron can only separate "on" from "off" by drawing one straight line across the grid. Try it: no single straight line puts both "on" corners on one side and both "off" corners on the other. The "on" corners sit diagonally opposite each other. One layer simply cannot learn XOR — the very gate that adds bits in your processor (Lesson 3.3). As you will see in the next lesson, the fix is to add more layers, exactly as you built XOR itself from several gates.
Rules versus learning: what changes
| Rule-based program | Machine learning | |
|---|---|---|
| Who decides how it works? | A person writes every step | A person supplies examples and a goal; the program finds the pattern |
| Good at | Precise tasks: sums, records, bookings | Fuzzy tasks: faces, speech, language, spotting fraud |
| When it is wrong | Usually a clear mistake in the rules | Often surprising — it learned the wrong pattern |
| Can you see why it decided? | Yes, by reading the rules | Often hard: the "reasons" are millions of numbers |
| Depends on | The programmer's understanding | The quality of the examples |
That last row matters more than anything. A learned model is only as good as the examples it learned from. If the examples are wrong, narrow or unfair, the model will be too — a theme you will meet again in Lesson 10.4.
Training and using: two different jobs
Machine learning happens in two stages, and they are very different:
- Training is slow and enormous. It means running through vast amounts of training data, adjusting the numbers again and again. Large models are trained on huge numbers of powerful computers in data centres (Lesson 7.4), over weeks or months.
- Using the model — called inference — is quick by comparison. The finished numbers are applied to one new input: Adaeze's face this morning, the email that just arrived, the question you just typed.
And the finished model, all those learned numbers, is stored like any other data: as bytes in a file (Lesson 6.1). The face-recognition model on Adaeze's phone was trained somewhere else, long before she bought it; what her phone holds is the result — a file of numbers that, when her camera's pixels are fed through it, says "yes, that's her".
Where you already meet machine learning
Once you know what to look for, you will see machine learning everywhere:
- Face and fingerprint unlock on phones.
- Keyboard suggestions for the next word.
- Spam filters that keep scam emails out of your inbox.
- Feeds and recommendations that choose what video or post to show you next.
- Voice typing and automatic captions.
- Translation between languages.
- Fraud checks that flag a card payment that doesn't look like you.
- Chat assistants — including, in this course, the ELI5 tutor — which the rest of this module explains.
None of them is following a list of rules a person wrote for that exact task. All of them are applying patterns found by training on examples.
Common mistakes
| The mistake | Why it is wrong | What to do instead |
|---|---|---|
| "AI is a new kind of machine" | It runs on the same processors, memory and arithmetic as everything else | Think: ordinary computers, doing a lot of multiplying and adding |
| "Someone programmed the AI to recognise faces" | People programmed it to learn; the pattern came from examples | Separate "the learning program" from "what it learned" |
| "Machine learning is brand new" | Samuel's checkers and Rosenblatt's perceptron date from the 1950s | Know the history: the ideas are old; the computing power is new |
| "A trained model is always right" | It is only as good as its examples | Expect surprising mistakes |
| "Training happens on my phone every time I use it" | Training is mostly done in advance, in data centres | Your device mostly uses a finished model |
The short version
- Rule-based programs follow steps people wrote. Faces, voices and language can't be captured by hand-written rules.
- Machine learning learns from examples: it adjusts its numbers whenever it is wrong. The examples are the training data; the learned numbers are the model. It works because pictures, sounds and text are all numbers.
- IBM's Arthur Samuel named "machine learning" in a 1959 paper about a checkers program that came to beat him. Rosenblatt's perceptron, shown in July 1958, taught itself to sort punch cards.
- A single-layer perceptron can't learn XOR — no single straight line separates its corners. More layers fix that.
- Training is slow and done in data centres; using a model (inference) is fast. A model is stored as a file of numbers.
Try it yourself
See the difference between rules and learning.
- Try to write five rules that would tell a cat photo from a dog photo. Then think of a photo that would break each of your rules. What does that tell you?
- Draw the XOR grid with its four corners. Try every straight line you can think of to separate "on" from "off". Explain in one sentence why it can't be done.
- List five places you met machine learning today. For each, say what the input was (a photo, your voice, your typing…) and what the model decided.
- Write the rule-based spam filter "if the message contains FREE MONEY, it's spam". Then write three spam messages that would get past it.
- Explain to someone the difference between training a model and using one, with Adaeze's face unlock as the example.
You'll know you've got it when you can explain why nobody writes the rules for recognising a face, how a program can find the pattern from examples instead — and why that program is still just ordinary arithmetic on numbers.
More free previews
- ▶What a computer actually is15 min
- ▶Counting in twos15 min
- ▶Yes, no and the logic of every decision20 min
- ▶Opening the box20 min
- ▶From numbers to words: how people talk to processors25 min
- ▶What a file really is20 min
- ▶How bits travel: wires, light and radio20 min
- ▶What really happens when you open a web page20 min
- ▶How passwords are stored, and cracked25 min
- ▶The whole journey: from a tap in Lagos to a screen in London25 min