Settings

Theme
Lite Mode (saves mobile data)

In Lite Mode, animations and videos don't play until you tap them, and their size is shown first. Interactive widgets still work.

Text size

Back up or move your progress →

Part 0: Start Here

Kinds of learning

P0.325 min●○○ BeginnerReviewed Nov 30, 2026

Why this matters for machine learning

The first question to ask about any ML problem is: what is the learning signal, the thing that plays the role of the right answer? The answer sorts almost every method in this course into one of four kinds, and tells you what data you must collect.

  • Supervised learning, with labelled examples, is the setup behind most practical ML: predicting prices, spotting spam, reading medical images. (P3.A1: The supervised learning setup, coming soon)
  • Clustering and PCA find structure in data that has no labels. (P3.C1: k-means clustering, coming soon)
  • Self-supervised learning (predict the next word) is how large language models get their first, biggest stage of training. (P10.B2: The pretraining objective and loss curves, coming soon)
  • Reinforcement learning, from rewards, is used to tune chatbots with human feedback (RLHF) and to train game-playing agents. (P10.D2: Reward models and RLHF, coming soon)

Before this: How a machine "learns"

After this lesson you can

  • Name the four kinds of learning and say, for each, what the data looks like, what it learns from and what it outputs
  • Tell classification from regression, and clustering from dimensionality reduction and anomaly detection
  • Explain precisely how self-supervised labels are made from raw data, and why this is not the same as having no labels to learn from
  • Say what plays the role of the "right answer" and of the loss (P0.2) in each kind
  • Explain why real systems, such as a chat assistant, combine several kinds

In P0.2 you ran the learning loop: predict, measure the loss, update. One part of that loop quietly needed something: the right answer. We handed the machine yy for every xx. But where does the right answer come from? A person? The data? Nowhere?

The answer splits machine learning into kinds. They differ in what plays the role of the right answer, and so in what data you must collect and what the model can do. There are four main kinds. Almost every method in this course belongs to one of them, and the best systems today use several at once.

The four kinds at a glance

Tap through the four tabs. Each shows a small picture of the data, then what the model learns from, what it outputs, examples, and where this course teaches it. The last two rows tie each kind back to the loop from P0.2.

Four kinds of learning

Supervised learning

Learn from examples that come with the right answer.

?labels: ● circle ■ square
What the data looks like
Inputs, each paired with a label (a person or a record supplied the answer).
What it learns from
The gap between the prediction and the label.
What it outputs
A label (classification) or a number (regression) for a new input.
Two examples
  • Spam or not spam for an email (classification).
  • The price of a house from its size and location (regression).
In the loop of P0.2
Right answer: The label that came with the example.
Loss: How far the prediction is from the label (for example, mean squared error from P0.2).
Where this course teaches it
P3.A1 (setup), P3.A2 (regression), P3.A7 (classification)
Four kinds of learning as four tabs (use the left and right arrow keys, or tap). Supervised: dots with labels (circle or square) and a new unlabelled dot. Unsupervised: unlabelled dots that form three groups. Self-supervised: a sentence whose last word is hidden; the hidden word is the answer. Reinforcement: an agent in a small grid that earns +1 at the star and −1 at the cross.

We now go through each kind slowly.

Supervised learning: learn from labelled examples

Supervised learning is what P0.2 did. Every training example is a pair: an input x\mathbf{x} and its label yy, the right answer. The model predicts y^\hat{y}, the loss measures the gap to yy, and the update shrinks it. The label acts like a teacher who marks each answer, which is where the name comes from.

There are two main shapes of supervised problem, depending on what the label is:

  • Classification: the label is a category. Is this email spam or not? Which of the digits 0 to 9 is in this picture? Which of 1,000 object types is in this photo?
  • Regression: the label is a number. What will this house sell for? How many minutes will this delivery take? (P0.2’s line-fitting was regression.)

A quick test: ask whether “close” counts. If the answers are categories and a wrong one is simply wrong (“spam” vs “not spam”, “cat” vs “dog”), it is classification. If the answer is a quantity where being off by a little is much better than being off by a lot (a price, a temperature, a year), it is regression.

The catch is the labels. Someone must supply them: a doctor marking scans, a volunteer tagging photos, a customer’s recorded purchase. Labelling is often slow and costly, and the labels can contain mistakes that the model then learns. This cost is the main reason the other kinds exist. Collecting labels well is a topic of its own (P12.2).

The full setup is in P3.A1, regression in P3.A2 and classification in P3.A7.

Unsupervised learning: no answers, find structure

In unsupervised learning the data has no labels, only inputs. There is no right answer to compare with, so the model’s job is different: find structure that is already in the data. The three most common jobs:

  • Clustering: split the examples into groups of similar ones. Example: group customers by what they buy (P3.C1).
  • Dimensionality reduction: describe each example with fewer numbers, keeping what matters. Example: squeeze 100 measurements per example into 2 numbers you can plot (P3.C3, P3.C4).
  • Anomaly detection: learn what usual looks like, and flag what does not fit. Example: a sensor reading that does not resemble any normal reading (P3.C5).

Many unsupervised methods still have a loss. It is just computed from the data alone. In k-means clustering, for instance, the loss is how far each point is from the centre of its group, and the loop moves the centres to shrink it.

How do you know it worked? This is the hard part. With a supervised model you can compare predictions with held-back labels and count mistakes. With clustering, no label says “these 4 groups are the right ones”. Different algorithms, or the same one with different settings, give different groups, and none is “the truth”. People judge by scores computed from the data (how tight and well separated the groups are), by looking at the groups, and above all by asking whether the result is useful for the task. Treat unsupervised results as suggestions to examine.

Self-supervised learning: the data labels itself

Labels are expensive, but raw data is everywhere: the web holds an enormous amount of text and images. Self-supervised learning is a clever way to use it. We make the labels out of the data itself, by hiding a piece and asking the model to predict it:

  • Predict the next word of a text. (The answer is the word that really came next.)
  • Fill in a masked word. Hide a word in the middle, predict it from both sides. This is how the language model BERT was pretrained (Devlin et al., 2018): it hid about 15% of the tokens (word pieces).
  • Fill in hidden image patches. The masked autoencoder (He et al., 2021) hides a large share of an image’s patches (75%, in the paper’s main setting) and rebuilds them.

A worked example: one sentence becomes training pairs

Take the sentence “the cat sat on the mat”: 6 words. Using “predict the next word from the words so far”, it gives 5 training pairs. Nobody labelled anything. We just slid along the text:

PairInput (the context so far)Right answer (the next word)
1thecat
2the catsat
3the cat saton
4the cat sat onthe
5the cat sat on themat

In general, a sentence of nn words gives n−1n - 1 pairs (here 6−1=56 - 1 = 5). A large text collection therefore gives an enormous number of examples for free. The masked-word version makes pairs another way: from “the cat sat on the mat”, hide “sat” to get the input “the cat ___ on the mat” with the answer “sat”. Real systems split text into pieces called tokens, which are often parts of words, and use much longer contexts; this is a simplified picture (P10.A2).

Now look at the P0.2 loop. The prediction is a guess at the hidden word. The right answer is the hidden word. The loss measures how surprised the model is by it. The update nudges the parameters to be less surprised next time. It is exactly the supervised loop. That is why people say, precisely:

Why it matters. Because there is no labelling cost, self-supervised training can use vastly more data than labelling by hand ever could. This is the first stage of large language models such as GPT (P10.B2) and of many modern vision models (P5.16). To predict the next word well, a model must pick up grammar, facts and patterns in the text, and the numbers it learns turn out to be useful for many other tasks. Some people loosely call this “unsupervised” too, because no human labels exist. The two words are used inconsistently in the wild, so in this course “unsupervised” means “no target at all” and “self-supervised” means “targets made from the data”.

Reinforcement learning: learn from rewards

Now a different situation. A program plays a video game. There is no dataset of “correct moves”. It simply tries things and sees what happens. Reinforcement learning (RL) has a new cast of characters:

  • An agent that makes choices (the game-playing program, a robot).
  • An environment it acts in (the game, the room).
  • Actions the agent takes, and a reward, a number the environment gives back: points scored, +1 for reaching the goal, −1 for falling.

The agent’s goal is to collect as much reward as possible over time. What it learns is a policy: a rule that chooses an action in each situation. Some methods learn the policy directly; others learn how good each action is expected to be and then pick the best one (the Atari player in this lesson worked that way, P9.5). It learns by trial and error.

Two features make RL different from the kinds above:

  1. No right answer is ever given. The reward says how good the result was, not which action would have been best. Compare “that answer is wrong, it should be cat” (supervised) with “you scored 3” (reinforcement).
  2. Rewards can be delayed. In a chess game, the reward comes at the end (win or lose). The agent must work out which of its many earlier moves deserve credit or blame. This credit assignment problem is a core difficulty of RL.

The agent’s own actions also decide what data it sees next, so it must balance trying new things against repeating what already works (exploration versus exploitation, P9.2).

Famous examples: programs that learned to play Atari video games from the screen pixels and score (Mnih et al., DeepMind, 2013 and 2015), and AlphaGo, which beat the Go champion Lee Sedol 4 to 1 in 2016. The pipeline of AlphaGo is itself a mix: it first learned from expert human games (supervised), then improved by playing against itself (reinforcement). Its successor AlphaGo Zero (2017) used only self-play reinforcement learning, starting from random play, without human game data. RL is also used for robot control (often first in simulation) and, importantly for this course, to tune chatbots (see below).

RL gets a full Part of its own, P9.1 to P9.9. Its loss is built from rewards: actions that led to more reward are made more likely (P9.6).

The same data, seen four ways

A photo collection shows how the kinds differ. Same pictures, four different jobs:

KindWhat you do with the photosThe learning signal
SupervisedEach photo has a tag, “cat” or “dog”. Learn to tag new photos.The human tag
UnsupervisedNo tags. Group photos that look alike, and see what groups appear.None given; a score from the data
Self-supervisedNo tags. Hide patches of each photo and rebuild them.The hidden patch
ReinforcementNot a dataset: a robot with a camera tries to pick up a cat toy.Reward: +1 if it grasps the toy

The loop of P0.2, kind by kind

KindWhere the “right answer” comes fromWhat the loss measures
SupervisedA label supplied by people or recordsGap between prediction and label
UnsupervisedThere is noneHow well the structure fits the data (e.g. distance to group centres)
Self-supervisedHidden part of the dataGap between the prediction and the hidden part
ReinforcementNone; only a reward from the environmentBuilt from rewards: more reward is better (P9.6)

The loop is the same everywhere: guess, score, adjust. Only the source of the score changes. Note too that the kinds describe the training signal, not the model: the same neural network can be trained in any of these ways.

Real systems mix the kinds

Real systems rarely stick to one kind. Here are the main combinations.

Semi-supervised learning uses a few labelled examples and many unlabelled ones together. Suppose you have 1,000 labelled photos and 99,000 unlabelled ones. One common idea is to train on the labelled ones, let the model label the unlabelled ones it is confident about, and train on those too (“pseudo-labels”). It is useful when labels are scarce but raw data is plentiful. Pretraining on unlabelled data and then fine-tuning on a few labels (P5.10) has a similar spirit.

A chat assistant is built in stages. The best documented example is InstructGPT (Ouyang et al., 2022). OpenAI said that ChatGPT was trained with similar methods (RLHF), with small differences in how the data was collected. The InstructGPT recipe:

  1. Pretraining (self-supervised). A language model learns to predict the next word on a huge amount of text. This is the base model, GPT-3 in that paper (P10.B2).
  2. Supervised fine-tuning. People write example answers to prompts, and the model is trained to match them. These are labelled examples (P10.D1).
  3. Reinforcement learning from human feedback (RLHF). People rank several of the model’s answers. A reward model learns to score answers the way people do, and RL then adjusts the language model to earn higher scores (P10.D2).

So one assistant uses three kinds. Systems made after that paper are built in a similar spirit, but the details of closed models are not public, so we do not guess at them.

Two other ways to slice learning

Generative versus discriminative. This is a separate axis, not a fifth kind. A discriminative model tells things apart: given x\mathbf{x}, predict the label, which is p(y∣x)p(y \mid \mathbf{x}) (a spam filter). A generative model learns what the data itself looks like and can create new examples (a language model writing text, an image generator). You can have, for example, a supervised discriminative model (spam filter) and a self-supervised generative one (a language model). P8.1 treats this carefully.

Batch versus online. In batch learning you train on a fixed dataset, then freeze the model and use it (P0.2’s training versus inference). In online learning the model keeps updating as new data arrives, for example a system that adapts to changing user habits. Most deployed chatbots are used with their parameters frozen while you talk to them. Handling data that changes over time is covered in P12.5.

Which kind is it? A game

Eight real situations. Tap the kind of learning that fits. You get an explanation either way. Some real systems fit more than one kind in different stages, but each scenario here describes one stage.

Which kind of learning is this?

Scenario 1 of 8

An email filter is trained on 50,000 emails that people marked "spam" or "not spam", then labels new emails.

Pick the kind of learning that fits.

Solved 0 of 8
A game with eight scenarios. Read the scenario, then tap one of four buttons: Supervised, Unsupervised, Self-supervised or Reinforcement. A wrong answer gives a hint; a right answer gives the explanation. Use Next scenario to move on. Works by tap or keyboard.

Choosing a kind in practice

A rough guide to which kind fits a problem:

  • You have inputs and reliable labels for what you want to predict: supervised.
  • You have inputs only and want to explore or summarise: unsupervised.
  • You have a lot of raw data and want a general-purpose model: self-supervised pretraining, then adapt it.
  • The problem is a sequence of decisions with feedback over time: reinforcement.

Intuition

Think of how a child might learn. Supervised: a parent points at an animal and says “dog”. Unsupervised: the child sorts toys into piles on their own. Self-supervised: a child hears “the cat sat on the …” and guesses the next word, then hears it. Nobody corrected them: the sentence itself was the answer. Reinforcement: a child learns to ride a bike through wobbles and falls, with no one saying which muscle move was wrong.

Where it breaks: a human child mixes all four at once and understands what they are doing. A machine uses one defined signal and a loss. It can still pick up skills nobody named (a next-word predictor learns grammar and facts), but only ones that help it do better on that signal.

Math

The four kinds differ in the objective being minimised. With model parameters θ\boldsymbol{\theta} and a loss LL for one example:

  • Supervised: L(θ)=1N∑iL(fθ(xi), yi)\mathcal{L}(\boldsymbol{\theta}) = \frac{1}{N}\sum_{i} L\big(f_{\boldsymbol{\theta}}(\mathbf{x}_i),\, y_i\big), where yiy_i is a given label.
  • Unsupervised: L(θ)=1N∑iL(xi; θ)\mathcal{L}(\boldsymbol{\theta}) = \frac{1}{N}\sum_{i} L\big(\mathbf{x}_i;\, \boldsymbol{\theta}\big), with no yy. For example, k-means uses the squared distance from xi\mathbf{x}_i to its nearest centre.
  • Self-supervised: the same form as supervised, but yiy_i is a part of xi\mathbf{x}_i. For next-word prediction, with words x1,x2,…x_1, x_2, \dots: L=−1T∑tlog⁡pθ(xt∣x1,…,xt−1)\mathcal{L} = -\frac{1}{T}\sum_{t} \log p_{\boldsymbol{\theta}}(x_t \mid x_1, \dots, x_{t-1}), the average surprise at the real next word (P10.B2).
  • Reinforcement: the agent chooses actions with a policy, and the goal is to maximise the expected total reward, E[∑trt]\mathbb{E}\big[\sum_t r_t\big]. There is no label yy in this formula (P9.3 adds discounting).

Code

The loop is the same, only the “answer” changes. Self-supervised pairs from raw text need no labels: this code builds them for our sentence.

Try it: labels made from raw text

Runs real Python in your browser. First run downloads about 6 MB (once; your browser keeps it).

Change the sentence and watch the number of pairs. A sentence of nn words gives n−1n - 1 next-word pairs and nn masked-word pairs.

Go deeper Is self-supervised learning a kind of unsupervised learning?

Opinions differ, and the words are used inconsistently. The training data has no human labels, so some call it unsupervised. But the training procedure uses a definite target and a supervised-style loss, so many researchers keep it as its own kind. What matters is that you know what the signal is. You will see both usages in the wild, so check what an author means.

Go deeper Other names you will meet

Contrastive learning (P5.16, P8.13) is a self-supervised idea where the target is “these two views of the same thing should be close together, different things far apart”. Active learning is about choosing which examples a person should label next (P12.2). Transfer learning reuses a model trained on one task as the starting point for another (P5.10). Few-shot and meta-learning are in P11.6. Weak supervision uses noisy, cheap labels in place of careful ones.

Check yourself

Check your understanding

  1. A model is trained on one million photos that volunteers tagged "cat" or "dog", and then tags new photos. Which kind of learning is this?

  2. Which statement about self-supervised learning is the most accurate?

  3. In reinforcement learning, what does the agent get in place of the right action for each situation?

  4. In the InstructGPT paper (2022), which description of how the assistant models were built is correct?

  5. A company groups its customers into 4 clusters with no labels. Which statement is true?

Exercises

  1. Classification or regression? (a) The number of bikes rented tomorrow. (b) Whether a tumour is benign or malignant. (c) The year a photo was taken, as a number. (d) Which of 10 digits is written.
    Show answer(a) regression, (b) classification, (c) usually regression, because being off by 1 year is much better than being off by 50; you could also frame it as classification into decades, which is a design choice. It is a number on a scale, (d) classification.
  2. How many next-word training pairs does the sentence “I like to read books” give? How many masked-word pairs (hide one word at a time)?
    Show answer5 words, so 4 next-word pairs and 5 masked-word pairs.
  3. A hospital has 200 scans labelled by doctors and 20,000 unlabelled scans. Which kind of learning uses both, and why would you use it?
    Show answersemi-supervised. Labels are costly and scarce, but unlabelled scans are plentiful and add information about what scans look like.
  4. For a robot vacuum that learns a route, what could the reward be, and why is it hard that rewards are delayed?
    Show answerfor example +1 for each clean floor tile and a penalty for bumping. A bump may be caused by a turn several moves earlier, so the agent has to work out which earlier action to blame (credit assignment).
  5. In one sentence each, say what plays the role of the “right answer” and of the loss when a language model learns next-word prediction.
    Show answerthe right answer is the word that really came next in the text. The loss measures how surprised the model is by that word.
  6. A friend says “my spam filter is generative, so it is unsupervised”. What is wrong with this?
    Show answergenerative versus discriminative is a different axis from the kinds of learning. Whether a model is generative or discriminative does not decide whether it is supervised. A classic spam filter, Naive Bayes, is generative, and it is still supervised, because it is trained on emails labelled spam or not spam.
  7. Why is it hard to say whether a clustering of customers is “right”? Give one way to judge it anyway.
    Show answerno ground-truth labels exist to compare with. You can compute a score such as how tight the groups are, and check whether the groups are useful, for example whether they lead to better offers.

Key takeaways

  • Supervised learning: inputs come with labels, and the model learns to match them. Classification predicts a category; regression predicts a number. Labels usually cost human time and money.
  • Unsupervised learning: inputs only. The model finds structure: groups (clustering), a simpler summary (dimensionality reduction) or odd cases (anomaly detection). With no labels, judging whether the result is good is hard.
  • Self-supervised learning: the labels are cut out of the data itself (next word, a masked word, a hidden image patch). It is ordinary supervised-style training with automatically made labels, and it lets models learn from huge unlabelled data.
  • Reinforcement learning: an agent acts, receives rewards (often late), and learns by trial and error which behaviour earns more reward. Nobody tells it the right action.
  • Mixes are the norm. Semi-supervised learning uses a few labels plus many unlabelled examples. A chat assistant is built in stages: self-supervised pretraining, supervised fine-tuning, then reinforcement learning from human feedback.
  • Generative versus discriminative (making new data versus telling things apart) is a separate axis from these four kinds.
Found a mistake? Tell us