Ages

Now you know how AI learns from examples!

What next?

Try it yourself ↓

How does AI work?

▶ 4:48 video · Watch on YouTube

  1. 0:00 Start
  2. 0:39 Learning from examples
  3. 1:21 A network of dials
  4. 2:06 Training: nudging the dials
  5. 2:49 When AI gets it wrong
  6. 3:32 How chatbots work

Your turn

Train a tiny AI yourself

Play with the cat-and-dog computer!

Each lab is one step from the video. The network in these labs is real: it learns right here in your browser.

Each lab isolates one idea. The network is a real 2-input, 4-hidden-unit model trained by gradient descent in your browser; the features and data are simulated.

Tap the buttons and see what happens.

1

Write rules for a cat

Hand-written rules vs messy data

Cat or dog?

Switch rules on and off. Can you find a set that never gets it wrong?

Combine the rules. Is there any combination that classifies all three animals correctly?

Tap a rule. Does the computer get it right?

2

Add labelled examples

Features and labels

Lots of pictures

Add cats and dogs. Where do the cats land? Where do the dogs land?

Add labelled examples. Where do the two classes cluster, and where do they overlap?

Add cats. Add dogs. Where do they go?

Two made-up features, simulated examples. Real systems use far more of both.

3

Turn the dials

One neuron: weighted sum and threshold

Turn the two dials, then switch animals. Can you make it say cat for the cat and dog for the beagle?

Find weights that separate the cat from the beagle. Why does the fluffy dog still end up on the wrong side?

One simplified unit: it fires when the weighted sum is over 1.

4

Train the network

Watch gradient descent

Guess, check, fix

Press Train and watch the error fall. Then scramble the dials and train again.

Train, scramble, retrain. Does it always find the same boundary? Watch the loss curve flatten.

Press Train. Watch the computer get better!

A real tiny network, trained in your browser on the 60 simulated examples.

5

Fool the network

Find the failure cases

Trick the computer

Drag the “?” around the chart. Then switch to lopsided examples. What changes?

Probe the boundary, then retrain on the skewed data set. Where does the model become confidently wrong?

Tap Fluffy dog. What does the computer say?

Lopsided = the same cats, but only 5 floppy-eared dogs.

6

Build a sentence, word by word

Next-token prediction

Next word, please!

Click a word to add it. Pick the likely one, or a surprising one.

Choose the next word or phrase yourself. Probabilities in the first row come from a machine-learning course example; the second row is illustrative.

Tap a word to finish the sentence.

First row: example probabilities from a machine-learning course. Second row: illustrative.

How does AI work?

AI means a computer doing jobs that seem clever, like telling a cat from a dog. Many AIs are not told all the rules. They learn!

1. Rules don't work

"Pointy ears means cat" sounds like a good rule. But some dogs have pointy ears too. Every rule makes some mistakes.

2. Lots of examples

So we show the computer lots and lots of pictures. Each one has a name tag: cat or dog. The computer finds the pattern by itself.

3. Guess, check, fix

At first the computer just guesses. We check each guess, and it fixes itself a tiny bit. Again and again! Soon it gets most of them right.

4. It can still be wrong

A fluffy dog with pointy ears can trick it. The computer only knows its pictures. It doesn't really know what a dog is.

5. Talking computers

Some computers can chat. They learned from a giant pile of words, and they guess the next word, one at a time. A guess can sound sure and still be wrong.

Did you know? A computer once thought a toy turtle was something totally different. Even clever computers can be fooled!
Good to know: AI can help you, but it can make things up. Always check with a grown-up.

← More explainers

How does AI work? The short answer

Most modern AI learns from examples instead of following rules that a programmer wrote. In the most common kind, you show a computer lots of data with the right answers attached, such as thousands of photos labelled "cat" or "dog". It hunts for patterns that go with each answer, then uses those patterns to guess about things it has never seen.23 This way of building AI is called machine learning. Computers learn from data without being explicitly programmed for each task.1417

The learning usually happens inside a neural network: layers of simple units joined by connections with adjustable strengths, called weights. Training nudges those weights, over and over, until the network makes fewer mistakes.34 Chatbots like ChatGPT use the same idea at a huge scale. They are trained to predict the next word.911

What is artificial intelligence?

Britannica defines artificial intelligence as the ability of a computer or robot to do tasks we usually link with intelligent beings, such as reasoning, spotting meaning, generalizing or learning from experience.1 You already use it every day. Voice assistants, handwriting recognition, search engines, translation apps, song recommendations and chatbots all rely on AI.12

Some AI programs now match human experts at specific tasks. But no program yet matches the full, flexible, everyday understanding a person has across many different kinds of problem.1

Why rules don't work: the cat-and-dog puzzle

Try writing rules to tell a cat from a dog. "Pointy ears means cat" fails on a husky or a Pomeranian. "Short snout means cat" fails on a pug. Every rule you add has exceptions. Real-world tasks like understanding speech or recognizing faces have far too many exceptions for hand-written rules.

Machine learning flips the problem around. Instead of telling the computer how to decide, you give it examples and let it work out the pattern itself. Google's course compares this to a student who studies old exams that come with the answers. After enough practice, the student is ready for a new exam.2 This is called supervised learning, because a human has labelled the examples with the correct answers.2

Kind of machine learningHow it learnsExample
SupervisedFrom examples labelled with the right answersIs this email spam? Is this a cat?
UnsupervisedFinds groups in data with no labelsGrouping similar shoppers
ReinforcementTries actions and gets rewards or penaltiesLearning to play a game
Generative AILearns patterns so it can make new contentWriting text, making images

The four categories are from Google's Machine Learning Crash Course.2

What is a neural network?

A neural network is made of simple processing units, called nodes, arranged in layers. Big networks have thousands or even millions of them. The design is loosely modelled on the brain.3 Data goes in at one end (the input layer), passes through one or more hidden layers, and comes out at the other end as an answer (the output layer).3

Here is what one node does:3

  1. Each incoming connection has a number called a weight.
  2. The node multiplies each incoming number by its weight.
  3. It adds the results together.
  4. If the total is above a threshold, the node "fires" and passes a signal on to the next layer.

output = fire? ( input₁ × weight₁ + input₂ × weight₂ + … )

That's it: multiply, add, decide. A single node is simple. The power comes from wiring huge numbers of them together in many layers.3 The "deep" in deep learning means many layers: ten, fifteen, even fifty in MIT's description.3 Neural networks can find curved, complicated dividing lines in data that a single straight rule never could.5

The idea isn't new. Warren McCulloch and Walter Pitts described the first mathematical model of a neuron in the 1940s (1943 in IBM's account, 1944 in MIT's). They took off in the 2010s, helped by graphics chips (GPUs), the kind used for video games, which turned out to be very good at running neural networks.3

How does AI learn? Training, step by step

A brand-new network knows nothing. Its weights start out as random numbers, so its first guesses are junk.3 Training fixes that with a loop called gradient descent:4

  1. Guess: run the training examples through the network.
  2. Measure: work out how wrong the guesses are. This number is called the loss (or error).
  3. Nudge: work out which way each weight should move to make the loss smaller, and move it a small amount.
  4. Repeat until the loss stops going down.

For networks with many layers, the maths that works out each weight's nudge is called backpropagation.5 If you plot the loss as training goes on, it usually drops quickly at first, then more slowly, and then levels off. Engineers say the model has converged.4 In the "Train the network" lab below the video, you can press "Train" and watch this happen to a real (tiny) network in your browser.

The goal isn't to memorize the training examples. It's to do well on new ones. A model that memorizes its examples but fails on new data is overfitting, like a student who memorized last year's answers without understanding them.6

How do chatbots like ChatGPT work?

Chatbots run on large language models (LLMs). A language model estimates how likely each possible next word (or piece of a word, called a token) is to come next in a piece of text.9 Google's course gives this example. For "When I hear rain on my roof, I ___ in my kitchen", a model might score:9

Possible next wordsProbability
cook soup9.4%
warm up a kettle5.2%
cower3.6%
nap2.5%
relax2.2%

The chatbot picks one of the likely options, adds it to the text, and does it all again for the next piece of text. Repeat that word after word, and you get sentences, answers, translations and summaries.9

What makes it "large" is scale. LLMs are trained on billions or even trillions of words from books, articles, websites and code, and they can have billions of weights.10 Most use a design called the transformer, introduced by Google researchers in 2017. It lets the model weigh how every word in the text relates to every other word, which helps it keep track of context.12 After this first training, models are usually fine-tuned on smaller sets of example answers to make them more helpful.10

Why does AI get things wrong?

Hallucinations

A chatbot is built to produce text that sounds likely, not to check whether it is true. IBM puts it simply: a generative AI doesn't "know" what is true or false; it only "knows" what fits the pattern.11 When it's missing information, it can make up something plausible, like a fake fact or a source that doesn't exist. This is called a hallucination. In 2023, a US lawyer used a chatbot to find legal cases and filed them in court. Several of the cases turned out to be entirely invented.11 Hallucinations can be reduced, but they can't be completely eliminated.11

Trick examples

Image AIs learn patterns, not what things really are, so an unusual example can fool them. In 2017, MIT students 3D-printed a toy turtle that an image classifier mistook for a rifle.7

Bias

An AI learns whatever is in its data, including its gaps. If a training set underrepresents a group of people, the AI can work worse for them. That matters when AI helps decide things like school admissions, bank loans or rentals. NIST, the US standards agency, stresses that bias also comes from the people and systems around the AI, not just the data.8

Does AI think like a human?

No. Inside, a neural network is multiplying and adding numbers.3 It can be astonishingly good at a narrow task, but it doesn't have the flexible, everyday understanding a person has.1 When a chatbot writes "I think", those are likely-sounding words, not proof that it thinks like a person.11 A good habit is to treat AI like a very well-read but unreliable helper: useful for ideas and drafts, but always check the facts.

How to use AI safely

A chatbot can be a useful helper for ideas and practice, but check what it tells you with a trusted source, such as a good book or website, or a grown-up you trust.1115 Keep your personal information safe: don't give away things like your full name, password or home address.15 What you type into a public chatbot can be seen by the company that runs it, so the UK's National Cyber Security Centre advises not to put sensitive information into it.16 If something a chatbot says makes you feel upset, worried or confused, tell a trusted adult.15

How is AI powered?

Big AI systems run on computer chips in huge buildings called data centers. Training and running big models takes a lot of electricity, plus water to keep the hardware cool.13 In 2022, data centers worldwide used about 460 terawatt-hours of electricity. That's roughly as much as France uses, and not all of it was for AI.13

Common misconceptions

"Programmers write a rule for everything the AI does." Modern AI learns its own patterns from examples. People choose the data and the design, not every rule.23
"A neural network is a digital brain." It's only loosely inspired by the brain. Each unit just multiplies, adds and passes a number on.3
"If a chatbot sounds confident, it must be right." It's built to sound plausible, not to be correct. Check important facts.11
"Computers are neutral, so AI can't be biased." AI learns from human-made data and can pick up its biases.8
"AI understands what it says." Today's AI has no program with full human flexibility or everyday understanding.1

FAQ

How does AI work, in simple words?

Most modern AI learns from examples instead of following rules a programmer wrote. It is shown lots of data, finds patterns in it, and uses those patterns to make a guess about something new, like whether a photo shows a cat or a dog, or which word should come next in a sentence.

Where does AI get its information?

From its training data. An image AI often learns from labelled pictures; a chatbot (a large language model) learns from billions of words of text such as books, articles, websites and code. It doesn't check its answers against a trusted list. Some chatbots can also search the web or read documents you give them, but their answers can still be wrong, so check important facts with a trusted source or a grown-up.

What is a neural network?

A neural network is a lot of simple units arranged in layers, loosely inspired by the brain. Each connection has a number called a weight. A unit multiplies its inputs by their weights, adds them up and, if the total is large enough, passes a signal on. Training adjusts the weights until the network's answers are mostly right.

How do chatbots like ChatGPT work?

They are large language models trained to predict the next word (or piece of a word) in a piece of text. Given your message, the model scores the possible next words, picks a likely one, and repeats, word after word. Extra training with human-written examples makes it more helpful.

Why does AI make mistakes or 'hallucinate'?

A chatbot is built to produce text that sounds likely, not to check whether it is true. When it lacks information, it can fill the gap with something plausible but made up. Image AIs can also be fooled by unusual examples that don't match the patterns they learned.

Does AI think like a human?

No. Today's AI is very good at specific pattern-matching tasks, but no program matches a person's flexible, everyday understanding of the world. A neural network is multiplying and adding numbers; sounding human is not the same as thinking or understanding the way a person does.

What's the difference between AI and machine learning?

Artificial intelligence is the big goal: computers doing tasks we associate with intelligence. Machine learning is the main way we get there today: training a model on data so it learns patterns instead of being given rules. Deep learning is machine learning with many-layered neural networks.

Is it safe for kids to use AI chatbots?

Use them only with a grown-up's OK, and check what they say with a trusted source. Never share your full name, address, school or passwords: what you type can be seen by the company that runs the chatbot.

Did this help it click?

Sources

  1. Encyclopaedia Britannica, Artificial intelligence
  2. Google for Developers, Intro to Machine Learning: What is ML?
  3. MIT News, Explained: Neural networks
  4. Google Machine Learning Crash Course, Gradient descent
  5. Google Machine Learning Crash Course, Neural networks (and Backpropagation)
  6. Google Machine Learning Crash Course, Overfitting
  7. MIT News, Why did my classifier just mistake a turtle for a rifle?
  8. NIST, There's More to AI Bias Than Biased Data (SP 1270)
  9. Google Machine Learning Crash Course, Introduction to large language models
  10. IBM, What are large language models?
  11. IBM, What are AI hallucinations?
  12. MIT News, Explained: Generative AI
  13. MIT News, Explained: Generative AI's environmental impact
  14. IBM, What is artificial intelligence?
  15. Childnet, Get SMART: staying safe online
  16. UK National Cyber Security Centre, ChatGPT and large language models: what's the risk?
  17. The Royal Society, Machine learning