Simple Algorithm
Machine Learning · Descent · 22 min

Supervised, Unsupervised & Beyond

The map of learning settings, from labels to rewards.

A spam filter, a customer-segmentation tool, the pretraining run behind a chatbot, a fraud detector that improves as it flags payments and a game-playing agent all "learn from experience," yet they solve different mathematical problems. What separates them is not the model but the setting: what the learner observes, who chooses the data, when it arrives and how success is scored.

What you’ll learn

  • State the protocol and the objective of supervised, unsupervised, semi-supervised, self-supervised, active, online and reinforcement learning.
  • Name the optimal predictors that regression and classification estimate, and the objectives that clustering, PCA and density estimation optimize.
  • Prove that minimizing next-token cross-entropy is maximum-likelihood density estimation, using the chain rule of probability.
  • Define regret and label complexity, and compute the label savings of binary search over passive learning for threshold classifiers.

Four questions that define a setting

The Learning Problem fixed one protocol: nature draws examples (xi,yi)(\mathbf x_i,y_i) i.i.d. from an unknown distribution PP, the learner sees all nn of them at once, and its output hh is judged by the risk R(h)=E[ℓ(h(x),y)]R(h)=\E[\ell(h(\mathbf x),y)] on fresh data. Every other setting in machine learning changes the answer to at least one of four questions:

  1. What is observed? Inputs with labels, inputs alone, or a reward for an action the learner took.
  2. Who chooses the examples? Nature, at random; the learner itself; or an adversary.
  3. When do they arrive? All at once (batch), or one at a time with a prediction due before each answer (online).
  4. How is success scored? Risk on new data, likelihood of held-out data, regret against the best fixed predictor in hindsight, or total reward.
SettingThe learner observesWho picks the dataScored by
Supervisedpairs (xi,yi)(\mathbf x_i,y_i)nature, i.i.d.risk R(h)R(h) on new data
Unsupervisedinputs xi\mathbf x_i onlynature, i.i.d.an objective on P(x)P(\mathbf x): inertia, reconstruction error, held-out log-likelihood
Semi-superviseda few pairs plus many unlabeled inputsnature, i.i.d.risk
Self-supervisedinputs, with targets cut from the inputs themselvesnature, i.i.d.performance after transfer to a downstream task
Activeunlabeled inputs; labels on requestthe learnerrisk per label bought
Onlineone example per round, its label after the predictionnature or an adversaryregret
Bandits and reinforcementa reward for the chosen action onlythe learner's own actionsregret, or expected total reward
Typical methods: least squares, logistic regression, trees and networks (supervised); k-means, PCA and mixture models (unsupervised); label propagation and pseudo-labels (semi-supervised); next-token, masked-token and contrastive prediction (self-supervised); uncertainty sampling and disagreement-based querying (active); the perceptron, multiplicative weights and online gradient descent (online); UCB, Thompson sampling, Q-learning and policy gradients (bandits and RL).
Check your understanding

A news site shows each visitor one headline and records whether it was clicked. It wants to learn which headline to show to whom. Why is this not ordinary supervised classification?

  1. The clicks are too noisy to serve as labels
  2. The site observes the outcome only for the headline it chose to show, so its own choices decide which data it collects
  3. There are no input features, only clicks
  4. A click is a continuous outcome, so the task must be regression
Show the answer

B. The site observes the outcome only for the headline it chose to show, so its own choices decide which data it collects

Feedback is partial. The click (or its absence) is recorded for the shown headline only; what the visitor would have done with any other headline is never observed, and the site's own choices determine which outcomes it sees. That is a contextual bandit problem: the learner must explore to learn, and naive accuracy on logged data is biased toward whatever the old policy chose to show.

Supervised learning: regression, classification, structure

In supervised learning the training set D={(xi,yi)}i=1n\data=\{(\mathbf x_i,y_i)\}_{i=1}^n is drawn i.i.d. from PP, and the learner picks hh from a hypothesis class H\mathcal H to make the risk small, usually by empirical risk minimization. The type of yy names the task. In regression y∈Ry\in\R and the default loss is squared error; in classification yy is one of KK classes and the score that matters is the 0–1 loss. Each loss has a best possible predictor, derived in The Learning Problem:

f∗(x)=E[ y∣x ]  (squared loss),h∗(x)=arg max⁡k P(y=k∣x)  (0–1 loss)f^*(\mathbf x)=\E[\,y\mid\mathbf x\,]\ \ \text{(squared loss)},\qquad h^*(\mathbf x)=\argmax_{k}\,P(y=k\mid\mathbf x)\ \ \text{(0–1 loss)}
Regression estimates a conditional mean, classification a conditional mode. The 0–1 loss has zero gradient almost everywhere, so classifiers are trained on convex surrogates such as the log loss or the hinge loss and then thresholded.

Structured outputs. Sometimes yy is itself a combinatorial object: a tag for every word of a sentence, a parse tree, a set of bounding boxes, a segmentation mask. With LL positions and KK tags there are KLK^L possible outputs, so models factorize the score over parts (conditional random fields) or generate yy one piece at a time, p(y∣x)=∏tp(yt∣y<t,x)p(y\mid\mathbf x)=\prod_t p(y_t\mid y_{<t},\mathbf x). Losses decompose too: the Hamming loss counts the wrong positions instead of charging 1 for any mistake.

Two ways to model. A discriminative model learns p(y∣x)p(y\mid\mathbf x) or a decision rule directly (logistic regression, support vector machines). A generative model learns p(x∣y)p(\mathbf x\mid y) and p(y)p(y) and classifies by Bayes' rule (naive Bayes, linear discriminant analysis). When each pays off is a lesson of its own in the Linear Models topic.

Unsupervised learning: structure in P(x)

In unsupervised learning the data are inputs alone, x1,…,xn\mathbf x_1,\dots,\mathbf x_n drawn i.i.d. from PxP_{\mathbf x}, and the goal is to describe PxP_{\mathbf x} itself. Three tasks dominate, and each is defined by the objective it optimizes:

TaskObjectiveClassic method
Clusteringmin⁡μ1,…,μk∑imin⁡j∥xi−μj∥2\min_{\boldsymbol\mu_1,\dots,\boldsymbol\mu_k}\sum_i\min_j\norm{\mathbf x_i-\boldsymbol\mu_j}^2, the inertiak-means (Lloyd's algorithm)
Dimensionality reductionmin⁡V⊤V=Ik∑i∥xi−VV⊤xi∥2\min_{V^\top V=I_k}\sum_i\norm{\mathbf x_i-VV^\top\mathbf x_i}^2 for centered dataPCA: the top kk eigenvectors of the covariance matrix
Density estimationmax⁡θ∑ilog⁡pθ(xi)\max_{\boldsymbol\theta}\sum_i\log p_{\boldsymbol\theta}(\mathbf x_i)mixture models, kernel density estimates, normalizing flows
For PCA, minimizing reconstruction error is the same as maximizing the variance kept, because ∥x∥2=∥VV⊤x∥2+∥x−VV⊤x∥2\norm{\mathbf x}^2=\norm{VV^\top\mathbf x}^2+\norm{\mathbf x-VV^\top\mathbf x}^2 for every point (Pythagoras). The Math Toolkit and its Convergence lesson on the SVD prove that the top eigenvectors solve it.
Think first Without labels, how can you judge a density model, or a clustering?

Density models have a real yardstick: the average log-likelihood of held-out data estimates −H(Px)−DKL(Px ∥ pθ)-H(P_{\mathbf x})-\KL(P_{\mathbf x}\,\|\,p_{\boldsymbol\theta}), so comparing models on it compares their KL divergences from the truth. Clusterings have weaker ones: stability across restarts and subsamples, internal scores such as the silhouette, agreement with a few labels if you have them, and above all usefulness for the task downstream. There is no universally right clustering: the Unsupervised Learning topic presents Kleinberg's theorem that no clustering rule can satisfy three natural axioms at once.

Labels for free: self-supervised learning and transfer

Labels cost money and expertise; raw text, images and audio are nearly free. Self-supervised learning manufactures a supervised problem from unlabeled data: hide part of each input and train a model to predict it from the rest. Language models predict the next token. Masked models such as BERT predict masked-out words from the context on both sides (Devlin, Chang, Lee & Toutanova, 2019). Contrastive methods such as SimCLR train two augmented views of the same image to have nearby embeddings and views of different images to have distant ones (Chen, Kornblith, Norouzi & Hinton, 2020). No human labels anything, yet the training loop is ordinary supervised learning.

DerivationNext-token prediction is maximum likelihood
  1. p(x1,…,xT)=∏t=1Tp(xt∣x1,…,xt−1)p(x_1,\dots,x_T)=\prod_{t=1}^{T}p(x_t\mid x_1,\dots,x_{t-1})

    The chain rule of probability factorizes every distribution over sequences, exactly, with no modeling assumption:

  2. log⁡pθ(x1:T)=∑t=1Tlog⁡pθ(xt∣x<t)\log p_{\boldsymbol\theta}(x_{1:T})=\sum_{t=1}^{T}\log p_{\boldsymbol\theta}(x_t\mid x_{<t})

    So a model's log-likelihood of a sequence is a sum of next-token log-probabilities. Each term is the log loss of a classifier whose input is the prefix x<tx_{<t} and whose label is the next token xtx_t:

  3. min⁡θ −∑s∑tlog⁡pθ(xt(s)∣x<t(s))⟺max⁡θ ∑slog⁡pθ(x(s))\min_{\boldsymbol\theta}\ -\sum_{s}\sum_{t}\log p_{\boldsymbol\theta}\big(x^{(s)}_t\mid x^{(s)}_{<t}\big)\quad\Longleftrightarrow\quad\max_{\boldsymbol\theta}\ \sum_{s}\log p_{\boldsymbol\theta}\big(x^{(s)}\big)

    Summed over a corpus of sequences x(s)x^{(s)}, the next-token cross-entropy is therefore the negative log-likelihood of the corpus. Minimizing it is maximum-likelihood density estimation, an unsupervised objective, carried out as a chain of supervised classification problems:

  4. Ex∼p[−log⁡pθ(x)]=H(p)+DKL(p ∥ pθ) ≥ H(p)\E_{x\sim p}\big[-\log p_{\boldsymbol\theta}(x)\big]=H(p)+\KL(p\,\|\,p_{\boldsymbol\theta})\ \ge\ H(p)

    With unlimited data and an unrestricted model, the minimizer is the data distribution itself: the expected log loss splits into an entropy that no model can beat plus a KL divergence that vanishes only when pθ=pp_{\boldsymbol\theta}=p (proved in Information Theory for ML):

Transfer learning is how the investment pays off. Pretrain a representation φ(x)\varphi(\mathbf x) on a large self-supervised task, then reuse it on a small labeled one: train a linear classifier on φ(x)\varphi(\mathbf x) (a linear probe), or fine-tune all the weights with a small learning rate. It works when the pretext task forces φ\varphi to encode what the downstream task needs, and it can hurt (negative transfer) when it does not.

Semi-supervised learning sits between the settings: a few labeled pairs and many unlabeled inputs from the same distribution. Unlabeled points reveal only PxP_{\mathbf x}, so they can help only if PxP_{\mathbf x} says something about P(y∣x)P(y\mid\mathbf x), for instance when the classes form clusters separated by low-density gaps. When that link is missing, unlabeled data provably add little, and with a wrong model they can even hurt.

Check your understanding

An image model is pretrained on a billion unlabeled photos to tell whether two crops come from the same photo; then a linear classifier on its features is trained with 1,000 labeled photos. Where do the targets of the pretraining stage come from?

  1. From human annotators who labeled a subset of the billion photos
  2. From the 1,000 labeled photos, propagated to their nearest neighbors
  3. From the photos themselves: which crops share a source image is known by construction
  4. There are none: pretraining minimizes reconstruction error, as PCA does
Show the answer

C. From the photos themselves: which crops share a source image is known by construction

The pairing of crops is created by the data pipeline, so the targets are free and exact. That makes the stage self-supervised. The second stage, a linear classifier trained on 1,000 labels, is ordinary supervised learning on a transferred representation.

Learning from interaction: online, active, reinforcement

So far nature hands over i.i.d. data and the learner only computes. When the learner's own choices matter, the data stop being i.i.d., and new quantities measure success.

Online learning. In rounds t=1,…,Tt=1,\dots,T the learner receives xt\mathbf x_t, predicts y^t\hat y_t, then sees yty_t and pays ℓ(y^t,yt)\ell(\hat y_t,y_t). Nothing is assumed about how the sequence is generated, so an adversary may choose it. No learner can keep its absolute loss low against an adversary, so online learning measures loss relative to the best fixed hypothesis in hindsight:

RegretT=∑t=1Tℓ(y^t,yt)−min⁡h∈H∑t=1Tℓ(h(xt),yt)\mathrm{Regret}_T=\sum_{t=1}^{T}\ell(\hat y_t,y_t)-\min_{h\in\mathcal H}\sum_{t=1}^{T}\ell\big(h(\mathbf x_t),y_t\big)
Sublinear regret, RegretT/T→0\mathrm{Regret}_T/T\to0, means the learner's average loss approaches that of the best predictor in hindsight, on every sequence. Multiplicative weights over NN experts achieves O(Tln⁡N)\order{\sqrt{T\ln N}}, as Online Learning & Regret proves.

Active learning. The learner holds a pool of unlabeled inputs and pays for each label it requests, so it can ask about the most informative ones. Its cost is the label complexity: the number of labels needed to reach a target error. Take threshold classifiers on a line, hw(x)=1{x≥w}h_w(x)=\mathbf 1\{x\ge w\}, with labels that some threshold fits perfectly. Sorted by xx, the hidden labels read 0,0,…,0,1,…,10,0,\dots,0,1,\dots,1.

Predict before you look

A pool holds 1,000 unlabeled points on a line, and some threshold labels them perfectly. You may request labels one at a time, choosing each query after seeing the earlier answers. How many queries suffice, in the worst case, to find a threshold consistent with all 1,000 labels?

Show the answer

10 labels

The switch from 0 to 1 lies in one of 1,001 gaps (before the first point, between two neighbors or after the last). Querying the middle of the remaining stretch halves the candidate gaps, so after kk queries at most ⌈1001/2k⌉\lceil1001/2^k\rceil remain, and ⌈log⁡21001⌉=10\lceil\log_2 1001\rceil=10 queries suffice. A passive learner that pays for labels at random points has error of order 1/m1/m after mm labels, so it needs on the order of 1,000 labels for the same precision: log⁡2(1/ε)\log_2(1/\varepsilon) against 1/ε1/\varepsilon. The Convergence lesson Active Learning shows when such savings survive in higher dimensions and with noise; often they do not.

Bandits and reinforcement learning. Feedback arrives only for the action taken. A kk-armed bandit pays a random reward from the arm you pull, and you never learn what the other arms would have paid that round, so you must explore arms that look worse in order to exploit well later. Regret compares your total reward with always pulling the best arm. Reinforcement learning adds a state that your actions change: a policy π\pi maps states to actions and is scored by its expected discounted return E[∑t≥0γtrt+1]\E\big[\sum_{t\ge0}\gamma^t r_{t+1}\big] with 0≤γ<10\le\gamma<1, so a reward can depend on decisions made long before it arrives. The Artificial Intelligence course develops this in its topic Reinforcement Learning & Agents.

Key takeaways

  • A learning setting is fixed by four answers: what is observed, who chooses the data, when it arrives and how success is scored. Batch supervised learning on i.i.d. labeled pairs, judged by risk, is one point in that space.
  • Supervised learning estimates E[y∣x]\E[y\mid\mathbf x] (squared loss) or arg max⁡kP(y=k∣x)\argmax_k P(y=k\mid\mathbf x) (0–1 loss); structured outputs and the generative–discriminative choice are variations on that theme.
  • Unsupervised learning optimizes objectives on P(x)P(\mathbf x) (inertia, reconstruction error, likelihood) without an answer key. Self-supervised learning turns unlabeled data into supervised problems, and next-token prediction is exactly maximum-likelihood density estimation.
  • When the learner chooses its data, the data are no longer i.i.d.: online learning measures regret against the best fixed predictor in hindsight, active learning counts labels (log⁡2(1/ε)\log_2(1/\varepsilon) against 1/ε1/\varepsilon for thresholds), and bandits and reinforcement learning trade exploration against exploitation.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

An online algorithm guarantees RegretT≤3Tln⁡N\mathrm{Regret}_T\le3\sqrt{T\ln N} against NN experts on every sequence. What does this guarantee as TT grows?

  1. Its total loss stays below 3Tln⁡N3\sqrt{T\ln N}
  2. It eventually predicts every label correctly
  3. Its average loss per round approaches that of the best single expert in hindsight, whatever the sequence
  4. It matches the best expert only if the data are i.i.d.
Show the answer

C. Its average loss per round approaches that of the best single expert in hindsight, whatever the sequence

Dividing by TT, its average loss exceeds the best expert's by at most 3ln⁡N/T→03\sqrt{\ln N/T}\to0. The guarantee is relative: if every expert is bad, the learner is bad too, but never much worse than the best of them, even on adversarial sequences.

Question 2

A language model is trained to minimize the summed next-token cross-entropy on a corpus. Which statement is exactly true?

  1. It maximizes the likelihood of the corpus under the model, by the chain rule of probability
  2. It is supervised learning, because each next token is a label written by a human annotator
  3. It approximates k-means clustering of the sentences
  4. It minimizes the 0–1 error of predicting the next token
Show the answer

A. It maximizes the likelihood of the corpus under the model, by the chain rule of probability

log⁡pθ(x1:T)=∑tlog⁡pθ(xt∣x<t)\log p_{\boldsymbol\theta}(x_{1:T})=\sum_t\log p_{\boldsymbol\theta}(x_t\mid x_{<t}), so the summed next-token log loss is the negative log-likelihood of the sequences. Next-token training is maximum-likelihood density estimation, carried out as a chain of classification problems.

Question 3

For threshold classifiers on a line, with labels that some threshold fits perfectly, why does active learning need only about log⁡2(1/ε)\log_2(1/\varepsilon) labels where passive learning needs about 1/ε1/\varepsilon?

  1. Active learners are given a more reliable labeler
  2. Active learning uses a richer hypothesis class
  3. Passive learning must also pay to label its test set
  4. Sorted labels are monotone, so each well-placed query halves the set of thresholds still consistent with the answers
Show the answer

D. Sorted labels are monotone, so each well-placed query halves the set of thresholds still consistent with the answers

Random labels mostly fall far from the boundary and confirm what is already known; a query in the middle of the remaining uncertain stretch always rules out half of it. The argument does not extend to every class: Dasgupta (2005) gives two-dimensional examples where some targets need order 1/ε1/\varepsilon labels however the queries are chosen, which is why the Convergence lesson measures savings with the disagreement coefficient.

Question 4

A site logged which headline its current policy showed each visitor and whether it was clicked. To evaluate a new policy, you average the clicks over the visits where it would have shown the same headline as the logs. Why can this estimate be badly biased?

  1. Click logs are always too small to estimate anything
  2. The visits where the two policies agree are not a random sample: the old policy chose them, so they can differ systematically from all visits
  3. Bandit problems have no well-defined click rate
  4. It cannot be biased, since every click in it was really observed
Show the answer

B. The visits where the two policies agree are not a random sample: the old policy chose them, so they can differ systematically from all visits

The logging policy decided which outcomes exist. If it showed sports headlines mainly to sports fans, the agreeing visits over-represent sports fans. Weighting each logged outcome by one over the probability that the old policy chose that action (inverse propensity weighting) removes the bias, provided the old policy gave every action a positive probability.

Question 5

An online learner has regret o(T)o(T) on every sequence. Under which extra assumption does averaging its hypotheses give a single predictor whose risk is close to the best in the class?

  1. None: low regret already implies low risk
  2. The data are realizable by some hypothesis in the class
  3. The examples are drawn i.i.d. from a fixed distribution, and the loss is convex in the hypothesis
  4. The learner stops making mistakes after round T\sqrt T
Show the answer

C. The examples are drawn i.i.d. from a fixed distribution, and the loss is convex in the hypothesis

Risk only makes sense for a distribution. With i.i.d. examples, each round's loss is an unbiased estimate of the current hypothesis's risk, so the average risk of the iterates exceeds the best risk by at most E[RegretT]/T\E[\mathrm{Regret}_T]/T; for a convex loss, Jensen's inequality passes this to the averaged hypothesis. This online-to-batch conversion is proved in Online Learning & Regret.

Go deeper

Further reading

  • K. P. Murphy, Probabilistic Machine Learning: An Introduction (MIT Press, 2022), chapter 1.
  • O. Chapelle, B. Schölkopf & A. Zien (eds.), Semi-Supervised Learning (MIT Press, 2006).
  • N. Cesa-Bianchi & G. Lugosi, Prediction, Learning, and Games (Cambridge University Press, 2006).
  • R. S. Sutton & A. G. Barto, Reinforcement Learning: An Introduction, 2nd ed. (MIT Press, 2018).