You hear “AI”, “machine learning”, “deep learning” and “ChatGPT” in the same sentence, as if they all meant the same thing. They do not. Each is a smaller idea inside the one before it. By the end of this lesson you will know which is which, and why a program that learns is a different kind of thing from a program that follows rules.
Two ways to build a clever program
Imagine you must build a spam filter: a program that reads an email and decides “spam” or “not spam”. (Not-spam is often called ham.)
Way 1: write the rules. You think about what spam looks like and type it in. The simplest rule you can write:
If the email contains the word “free”, it is spam.
Way 2: learn from examples. You collect emails that people have already labelled as spam or ham, and let the computer work out for itself which words point towards spam.
Here are eight labelled emails (the numbers are tiny so you can follow every step) and what the one-line rule says about each:
| # | Truth | Rule says | Right? | |
|---|---|---|---|---|
| 1 | win free prize now | spam | spam | yes |
| 2 | free money now | spam | spam | yes |
| 3 | claim your free prize | spam | spam | yes |
| 4 | win cash prize now | spam | ham | no (missed spam) |
| 5 | meeting at noon | ham | ham | yes |
| 6 | lunch now with team | ham | ham | yes |
| 7 | are you free for lunch | ham | spam | no (a real email blocked) |
| 8 | project meeting notes | ham | ham | yes |
The rule is right on 6 of 8. You could fix it: add “prize”, “cash”, then add an exception for “lunch”… Every fix needs a person to notice the mistake and write a new rule, and the rules start to fight each other.
Now the learning way. For each word, count how many spam emails contain it, and subtract how many ham emails contain it. That number is the word’s score: positive means “points to spam”, negative means “points to ham”.
| Word | Score | Word | Score |
|---|---|---|---|
| prize | +3 | meeting | −2 |
| win | +2 | lunch | −2 |
| free | +2 | at, noon, with, team | −1 each |
| now | +2 | are, you, for | −1 each |
| money, claim, your, cash | +1 each | project, notes | −1 each |
(For example, “prize” is in 3 spam emails and 0 ham emails, so its score is 3 − 0 = +3. “free” is in 3 spam and 1 ham email: 3 − 1 = +2.)
To judge an email, add up the scores of its words. A total above 0 means spam, otherwise ham. Email 4, “win cash prize now”: 2 + 1 + 3 + 2 = 8, spam. Email 7, “are you free for lunch”: −1 − 1 + 2 − 1 − 2 = −3, ham. Nobody wrote a rule about “lunch”. The data did.
This learned filter is right on all 8 training emails. It also handles three emails it has never seen: “win cash now” (total 5, spam), “are you free for the meeting” (total −3, ham) and “claim your prize now” (total 7, spam). The one-line rule gets all three wrong.
A fair warning. This is a toy. With only 8 emails, getting them all right proves very little: a program can fit a small training set perfectly and still fail on new emails. Real filters learn from huge numbers of emails and are judged on emails they have not seen (P3.A4). Real systems also often mix rules and learning. The point here is only the difference in approach.
Intuition
Think of teaching a child to recognise dogs. You could hand over a rulebook (“four legs, fur, barks…”) and quickly find exceptions: a dog with three legs, a hairless dog, a fox. Or you could just point at many dogs and non-dogs and say “dog” or “not dog”. People are good at the second way, and so, it turns out, can computers be.
Where the comparison breaks: a child brings years of experience of the world. A learning program starts from nothing but its examples, so it can only be as good as those examples, and it can pick up quirks of them. In our toy data, “now” gets a +2 spam score only because it happened to be in 3 spam emails and 1 ham email.
Code
Run this to see the same two filters in code. It uses only the standard library. Edit the emails and run it again.
Runs real Python in your browser. First run downloads about 6 MB (once; your browser keeps it).
The first line of output is number of learned parameters: 19: the table above has 19 word scores. Those are the numbers training produced.
The vocabulary of learning
The spam example already contains the five words you will see in every lesson.
| Word | Plain meaning | In the spam filter |
|---|---|---|
| Data | The examples a system learns from. Examples that come with the right answer attached are labelled; the answer is the label. | The 8 emails, each labelled spam or ham |
| Model | The recipe that turns an input into an output. | “Add up the word scores. Above 0 means spam.” |
| Parameters | The numbers inside the model that are set by learning. | The 19 word scores |
| Training | Using data to find good values for the parameters. | Counting words in spam and ham emails to get the scores |
| Prediction (or inference) | Using the trained model on a new input to get an output. | Scoring “win cash now” and answering “spam” |
Two more words. A feature is a measurable property of an input that the model uses; here, which words appear in the email. In classic machine learning a person usually chooses the features (we chose “words”). In deep learning, the model learns its own features from raw input, which is a big part of why it is so powerful. You will see this in P0.2 and in Part 4.
Notice the order: training happens first, once (or from time to time). Prediction happens afterwards, every time someone uses the model. Training is usually the expensive step; a single prediction is usually cheap.
Three circles: AI, ML and DL
Now the main picture. Use the buttons to zoom in, one circle at a time.
In words:
- Artificial intelligence (AI) is the broad goal: computer systems that do things we would call intelligent if a person did them, such as playing chess, understanding speech, or writing text. It says nothing about how you build the system.
- Machine learning (ML) is one way of reaching that goal: the system learns patterns from data instead of following rules a person wrote. Our learned spam filter is machine learning.
- Deep learning (DL) is machine learning with neural networks that have many layers. A neural network is a model made of many small units (artificial neurons) joined in layers; you meet it in P4.1. “Deep” refers to the number of layers. The layers learn their own features: given pictures of faces, early layers tend to pick up simple things such as edges, and later layers combine them into parts and then faces.
Where does the circle stop being “deep”? There is no sharp line. A network with one layer of neurons is usually not called deep; networks with many layers clearly are. Do not worry about the exact boundary.
Where do generative AI and LLMs sit?
Generative AI means systems that create new content: text, images, audio, code. A large language model (LLM) is a very large deep-learning model trained on huge amounts of text to predict what comes next, and then usually tuned further to follow instructions; chatbots such as ChatGPT are built on LLMs. So LLMs sit inside deep learning, as the last zoom level shows (P10.A1 explains how they work).
Generative AI is a bit different. It describes what a system does, not how it is built, so it is not another circle in the picture. Today’s well-known generative systems are deep-learning models, but “generative” and “deep” are separate ideas. And much of AI is not generative at all: a spam filter, a face recognizer and a chess program create nothing.
Try it: sort the systems
Pick a system, then tap the circle (or the button) where it belongs. You get feedback each time, and a wrong answer comes with a hint.
Rules or learning: when to use which
Learning is not always better. Each approach has a place.
| Hand-written rules | Learning from data | |
|---|---|---|
| Needs | Someone who knows the rules and can write them down | Many examples (usually labelled) |
| Good when | The rules are few and clear (calculate tax, route a call), or you need to explain every decision | The rules are too many or too fuzzy to write: recognising faces, speech, spam |
| Weak when | The world is messy and there are endless exceptions | There is little data, or the data is biased or unrepresentative |
| When things change | A person edits the rules | You can often retrain on new examples (you still must collect and check them) |
| Explaining a decision | Usually easy: point at the rule | Often hard, especially for deep networks |
Real products often combine both: learned models for the fuzzy part, plain rules for the parts that must be exact or auditable.
Narrow AI and general AI
Every AI system in use today is narrow AI: built or trained for particular tasks, such as recognising speech, translating, recommending videos or playing a game. A chess program cannot drive a car, and a face recognizer cannot write an essay.
Artificial general intelligence (AGI) is the idea of a system that can learn and do any intellectual task a person can. It is a goal people discuss, not something that exists today, and there is no agreed definition or test for it. Experts disagree about how far away it is, or whether the idea is even the right way to think about progress. Nothing in this course depends on the answer.
Large language models blur the picture a little, because one model can write, translate, summarise and answer questions. They are still trained for a particular kind of job (predicting text), and they have clear limits. Stated carefully, today’s systems:
- can do impressive things on specific tasks, sometimes better than people on that task: recognising objects in photos, translating, summarising, writing code, playing board games;
- can fail in surprising ways: for instance an LLM can state something false in a confident tone (P10.G2), and a vision system can be fooled by changes a person would not notice (P5.17);
- depend on their training data, and may do worse on inputs unlike anything they saw in training;
- do not have a general understanding of the world in the way a person does. Exactly how to describe what they do or do not understand is a topic researchers argue about, so be wary of anyone who is certain either way.
Why did deep learning take off when it did?
Neural networks are an old idea (the perceptron is from 1958). They became the dominant approach to many problems only in the 2010s. Researchers commonly point to three things coming together:
| Ingredient | What changed |
|---|---|
| Data | Large labelled datasets and huge amounts of text and images online. For example, ImageNet (presented in 2009) has grown to over 14 million labelled images; the 1,000-class subset used in its yearly contest has about 1.28 million training images in 1,000 classes. |
| Compute | GPUs (graphics processors) turned out to be very good at the huge numbers of multiplications that neural networks need (P1.B6). AlexNet in 2012 was trained on GPUs. |
| Algorithms | Better ways of building and training networks: for example the ReLU activation and dropout (both used in AlexNet), and later the Transformer (2017). |
No single one of these is “the” reason, and historians and researchers weigh them differently. The pattern to remember: a many-layered network needs lots of data to learn from, lots of computing to train it, and good methods to make training work. Around 2012 all three were available at once.
A short history
Here is the story as a timeline. Scroll through it and tap events for more detail. Notice the two shaded AI winters.
Three things the timeline shows.
- AI began as a goal, not a method. In 1956 nobody had today’s learning methods. Early AI included both rules and learning. Some of the first learning programs, such as Samuel’s checkers player (1959), are from the same decade.
- AI winters are what happens when promises outrun results. Funding and interest fell sharply twice. They did not end the field: machine learning and neural-network research carried on, and LeNet (1989 to 1998) was working deep learning years before the boom.
- Progress comes in waves, driven by ingredients as much as by ideas. Backpropagation was known by 1986, but the big gains of 2012 needed big data and GPUs too.
Misconceptions
Go deeper Is there one official definition of AI?
No. Textbooks such as Russell and Norvig’s Artificial Intelligence: A Modern Approach describe four ways people have defined it: systems that think like humans, act like humans (the idea behind Turing’s test), think rationally (follow correct logic) and act rationally (do the best thing available to reach a goal). Different definitions put the edge of “AI” in different places. This is also why a very simple device such as a fixed-rule thermostat is a borderline case that people can disagree about. This course uses the common working definition from the circles picture and keeps examples to clear cases.
Go deeper The famous "without being explicitly programmed" quote
You will often see machine learning defined as “the field of study that gives computers the ability to learn without being explicitly programmed”, credited to Arthur Samuel. That exact wording is not found in his 1959 paper, “Some Studies in Machine Learning Using the Game of Checkers”. It is a common paraphrase. What the paper does say, in its abstract, is that a computer can be programmed so that it will learn to play a better game of checkers than the person who wrote the program. The paraphrase captures the idea well; just do not quote it as his exact words.
Go deeper Where does 'learning' end and 'programming' begin?
Our spam filter has a human-written part (count words, subtract, add up, compare with 0) and a learned part (the 19 scores). That is true of all machine learning: a person always decides the model’s shape, the data and how success is measured. What is learned is the parameters. In deep learning the model is far bigger and also learns its own features, but a person still chooses the architecture, the data and the training method. Part 4 and P0.2 make this precise.
Check yourself
Check your understanding
Which statement about AI and machine learning is correct?
The circles nest: machine learning is inside AI. A chess program or expert system built entirely from hand-written rules is AI but not machine learning, so “every AI system uses machine learning” and “exact synonyms” fail, and “a larger field than AI” reverses the nesting.
In the spam filter, what are the 19 word scores (such as prize = +3)?
Parameters are the numbers inside the model that training sets. The data are the emails, the labels are "spam" or "ham", and a prediction is the answer for one email.
Which of these is an example of deep learning?
Deep learning means neural networks with many layers. The rules are AI without learning, and the fitted line and the word counts are machine learning without a neural network.
What does "narrow AI" mean?
Narrow AI means a system designed or trained for specific tasks, such as chess or translation. “AI that can do any task a person can do” describes general AI, which does not exist today.
Which combination do researchers commonly point to when explaining why deep learning took off in the 2010s?
Data, compute and algorithms came together around 2012. Neural networks only loosely resemble the brain, the perceptron dates from 1958, and no law was involved.
Exercises
- Put each in the right place: AI but not ML, ML but not deep learning, or deep learning. (a) A translation program built from hand-written grammar rules and a dictionary. (b) A program that classifies flowers by comparing their measurements with labelled examples. (c) A neural network with many layers that transcribes speech.
Show answer
(a) AI but not ML: people wrote the rules. (b) ML but not deep learning: it learns from labelled examples, but there is no deep neural network. (c) Deep learning. - Using the word scores in the lesson, what total does “free prize now meeting” get, and is it classified as spam?
Show answer
free +2, prize +3, now +2, meeting −2 makes 5. Above 0, so spam. - Add a ninth training email, “free cash for lunch”, labelled ham. Which scores change, and to what?
Show answer
free goes from +2 to +1 (3 spam, 2 ham); cash from +1 to 0 (1 spam, 1 ham); for from −1 to −2; lunch from −2 to −3. All other scores stay the same. Now “free prize now meeting” totals 1 + 3 + 2 − 2 = 4, still spam. - Name the data, the model, the parameters, the training and the inference in the spam example.
Show answer
data: the labelled emails. Model: add up word scores and compare with 0. Parameters: the word scores. Training: counting words to get the scores. Inference: scoring a new email. - Put these in order, oldest first: AlexNet wins ImageNet, the Dartmouth workshop, the Transformer paper, the backpropagation paper in Nature.
Show answer
Dartmouth workshop (1956), backpropagation paper (1986), AlexNet (2012), Transformer (2017). - Pick a task: deciding whether a photo contains a cat. Why is writing rules for it hard, and what would you need to build a learned version instead?
Show answer
cats vary in colour, pose, size, lighting and background, and so many exceptions appear that the rules never end. A learned version needs many photos labelled “cat” or “no cat”, a model, and training. Check it on photos it has never seen. - Someone says “deep learning is just a copy of the human brain”. Give two reasons why that is misleading.
Show answer
an artificial neuron is a simple calculation, far simpler than a biological neuron; and networks are judged by how well they do a task on a computer, not by how closely they copy a brain. The brain inspired the idea, but it is not a description.
Further reading
- A. M. Turing, Computing Machinery and Intelligence, Mind, 1950.
- McCarthy, Minsky, Rochester and Shannon, A Proposal for the Dartmouth Summer Research Project on Artificial Intelligence (1955), reprinted in AI Magazine, 2006.
- LeCun, Bengio and Hinton, Deep learning, Nature, 2015.
- Russell and Norvig, Artificial Intelligence: A Modern Approach.