When rules run out: why computers need to learn
Some jobs are too messy to write rules for. See why, and how that leads to machine learning.
You have learned a lot about how computers work. They take in bits, follow clear instructions, and do billions of tiny steps a second. If you can write down the steps, a computer can do the job.
But what if you cannot write down the steps?
Jobs that rules handle well
Some jobs are perfect for rules:
- Add up a shopping bill.
- Sort a list of names alphabetically.
- Find the shortest route on a map.
- Play noughts and crosses perfectly.
For each of these, a clear list of steps always works. That is what normal programming is brilliant at.
Jobs where rules fall apart
Now try this: write rules to decide whether a photo shows a cat.
- "A cat has pointy ears." But so do foxes, and some cats have folded ears.
- "A cat has whiskers." You cannot see them in many photos.
- "A cat has four legs." Not if it is curled up asleep.
- "A cat is furry." So is a dog. And some cats are hairless.
Every rule you write has exceptions, and every exception needs another rule. You could write thousands and still be wrong.
It is the same for many jobs that people find easy:
- Reading handwriting. Everyone writes a 7 differently.
- Spotting spam email. A rule like "block emails that say free money" is beaten when spammers write "fr3e m0ney".
- Understanding speech. Voices, accents and background noise are all different.
- Driving a car. The world has too many surprises.
We know how to do these things, but we cannot explain our own steps. Try telling someone how you recognise your friend's face. You cannot, you just do.
A different idea: learn from examples
Instead of writing the rules, what if the computer found them itself?
- Collect lots of examples as a table of numbers (remember: everything can be numbers).
- Tell the computer what counts as a good answer.
- Let the computer practise, adjusting its own settings to do better.
Then the computer finds its own rules, hidden in thousands of numbers, that no person had to write. This is machine learning.
| Rules (normal programming) | Learning (machine learning) | |
|---|---|---|
| Who finds the steps? | A person | The computer, from examples |
| What you provide | The rules | Lots of data, and a goal |
| Best for | Clear, exact jobs | Messy jobs with lots of variety |
| Example | A calculator | Recognising faces in photos |
Learning is not always better
It is not magic, and it is not always the right tool:
- A calculator is perfect with rules. Nobody wants a calculator that "learns" 2 + 2 and sometimes gets it wrong.
- Learning needs lots of examples, and good ones.
- It can make mistakes and be hard to explain.
- It does what its data and rewards teach it. That is why you saw the puppy find loopholes.
Good engineers pick the right tool for each job. Often they combine the two.
You are ready
You now know the building blocks: bits, numbers, gates, processors, algorithms, programs and data. That is enough to understand what machine learning is really doing. In the next lesson, you will meet it.
You can also jump straight into Train the Puppy. The puppy has no rules. It learns its own by practice, and you set the rewards.
Words to know
- Rule
- A clear step or instruction written by a person.
- Exception
- A case that the rule does not cover.
- Machine learning
- Computers finding their own rules from examples or practice.
Check yourself
Give one job that rules are good at and one where rules fall apart.
Show the answer
Good: adding a bill, sorting names, finding a route. Bad: recognising a cat in a photo, reading handwriting, understanding speech.
Why is it hard to write rules for recognising a cat?
Show the answer
Every rule has exceptions, such as foxes with pointy ears or hairless cats, and you would need endless rules.
In machine learning, who finds the rules?
Show the answer
The computer does, by practising on lots of examples.
Is machine learning always better than normal programming?
Show the answer
No. For clear, exact jobs like a calculator, plain rules are better. Learning suits messy jobs with a lot of variety.