You can spot a cat in a split second. Pointy ears, whiskers, a swishy tail: easy! But try explaining to someone exactly how you know it is a cat and not a fox, a dog or a fluffy slipper. It is surprisingly hard. Computers have the same problem, and the clever way they solve it is one of the big ideas behind artificial intelligence, or AI.
Why you can't just write the rules
When you code in Scratch, you give the computer exact instructions: "move 10 steps", "if touching the edge, bounce". That works brilliantly for games. But what rules would you write for "is this a cat?"
- "If it has pointy ears, it is a cat." But foxes have pointy ears too.
- "If it has whiskers, it is a cat." So do rabbits and seals.
- "If it is furry and has four legs, it is a cat." Hello, dog!
Every rule you try has exceptions. And a cat curled up asleep, or photographed from behind, or half hidden under a blanket, might break all of them at once. Writing the rules by hand quickly becomes impossible.
Big idea: for some problems, it is easier to show a computer lots of examples than to tell it the rules.
Learning from examples
So instead of rules, programmers give the computer examples. Lots of them. Thousands of pictures labelled "cat" and thousands labelled "not a cat". This collection of examples is called training data.
The computer then looks for patterns that the cat pictures share and the other pictures don't. It might notice certain shapes, edges, textures and colours that often turn up together. Nobody tells it "look at the ears". It works out for itself which patterns are useful for telling the two groups apart.
This is called machine learning, because the machine learns from data rather than following rules a person wrote. The finished result is called a model. When you show the model a brand-new picture it has never seen before, it compares the patterns in that picture with what it learned and makes a guess, often with a score for how confident it is, such as "92% cat".
Guessing, checking, getting better
Here is the part that might surprise you. At the start of training, the computer is terrible at the job. Its guesses are basically random.
Then it goes round a loop, a bit like the "sense, think, act" loop a robot uses:
- Guess: look at a picture and guess "cat" or "not a cat".
- Check: compare the guess with the correct label.
- Adjust: change its settings a tiny bit so the next guess is more likely to be right.
It does this again and again, through all the examples, many times over. Each little adjustment helps a tiny bit, and after enough rounds the model can become very good at the task. You learn a bit like this too: every time you see a new animal and someone tells you its name, your brain gets a little better at recognising it next time.
When the computer gets it wrong
A model can only learn from the examples it is given. That means the training data really matters.
Imagine every cat picture you used was taken indoors on a sofa, and every "not a cat" picture was taken outside. The computer might accidentally learn "sofa means cat"! Show it a dog on a sofa and it could proudly announce "cat". It found a pattern, just not the one you wanted.
This is why people who build AI think carefully about their data:
- Lots of variety: cats of different colours, sizes and positions, in different places and lighting.
- Fair examples: the "not a cat" pictures should include tricky look-alikes, such as foxes and fluffy toys.
- Testing: check the model with pictures it has never seen, to find out if it really learned the right thing.
Tip for parents: this is a great way to talk about AI at home. AI tools are not magic and they are not always right. They make guesses based on the examples they learned from, so it is always worth checking what they tell you.
Try this at home: train your own model
You can train a real machine learning model in a few minutes, for free, in a web browser. Teachable Machine from Google (teachablemachine.withgoogle.com) lets you teach a computer to recognise things using your webcam. It uses the camera, so a grown-up should help set it up.
You won't need a cat. Try teaching it to tell the difference between two everyday objects, such as a spoon and a pencil:
- Choose Image Project, then Standard image model.
- Rename "Class 1" to Spoon and "Class 2" to Pencil.
- Hold the spoon up to the webcam and press Hold to Record to collect lots of example pictures. Move it around, turn it and tilt it.
- Do the same for the pencil.
- Press Train Model and wait a moment.
- Now hold up each object and watch the preview. Does it guess correctly?
Then be a scientist and experiment:
- What happens if you hold up something it has never seen, such as a cup?
- What if you only record five pictures of each object? Is it worse?
- Can you trick it? Try holding the spoon very close, or in a dark corner.
Try this at home: add a third class called Nothing and record pictures of the empty room. Does the model get better at knowing when nothing is there?
If you enjoy it, you have just done what AI engineers do every day: collect data, train a model, test it and improve it. You can find more ideas on our AI page.
The big takeaway
Computers don't recognise cats the way you do. They don't know what a cat is, what it feels like to stroke one, or why it purrs. They spot patterns in examples, very quickly and very many times. That is powerful, and it is also why the examples we give them matter so much.
Next time you see a cat, give yourself a pat on the back: your brain did in a blink what takes a computer thousands of examples to learn.
