Contents
02Two ways to learn: the painter and the critic
2.1Three distributions
Every labelled data set is a sample from a joint distribution p(x,y). By the product rule it factorizes in two ways:
The two sides suggest the two ways to learn.
Definition 1 (Generative and discriminative classifiers). A generative classifier models p(x,y)=p(y)\,p(x\mid y): a prior over classes and a model of how inputs are distributed within each class. It can generate examples x from each class y, and it classifies with Bayes’ theorem. A discriminative classifier models only p(y\mid x), or a direct map from x to y; it can only discriminate between classes (Murphy, 2022, §9.4).
More broadly, a generative model is any model of how the data are distributed, p(x) or p(x\mid\text{condition}), from which we can sample: a language model is a model of p(\text{text}), an image generator a model of p(\text{image}\mid\text{prompt}). The prompt plays the role of y.
2.2The cats and dogs
Figure 1 shows both views on a toy problem with two features, snout length and ear pointiness. The generative model (a) fits one Gaussian to the 13 cats and one to the 13 dogs. Because it has a full description of each class, it can draw new animals from it (the stars): this is what “generative” means. The discriminative model (b) fits logistic regression, which learns only where cats turn into dogs. It reports p(\text{cat}\mid x)=0.66 for the new photo at x=(0.16,0.30), but it has no idea what a cat looks like away from the boundary.
2.3More examples of the two views
Language. To tell English from French, a generative approach learns a model of English text and a model of French text and asks which one makes a sentence more likely. A discriminative approach learns cues that separate them (“the”, “les”, accents) and nothing else.
Elephants and dogs. The classic example of the Stanford CS229 notes: a discriminative algorithm such as logistic regression looks for a line that separates elephants from dogs; a generative algorithm builds a model of what elephants look like and a model of what dogs look like, and matches a new animal against both (Ng and Ma, 2023).
Medicine. A generative model describes how blood tests are distributed among healthy and sick patients, which also tells a doctor that a particular result is unusual for both. A discriminative model gives the probability of disease given the test results, which is often all that is needed for the decision.
2.4The posterior can be much simpler than the classes
Modelling p(x\mid y) means modelling everything about the inputs, including details that do not matter for the decision. In Figure 2, class 1 has two bumps, so its density needs at least two components. The posterior p(y\mid x), however, is a single smooth step at x\approx0.77: the left bump, far from class 2, does not influence the decision at all. A discriminative model never spends parameters on it. This is the main argument for discriminative models (Bishop, 2006, §1.5.4), (Murphy, 2022, §9.4.1).
Pause and think. A model gives you p(y\mid x) for every x. Can you compute p(x) from it? Can you compute p(x\mid y)?
Show the answer
No. By (1), p(x,y)=p(x)\,p(y\mid x), and p(y\mid x) says nothing about p(x): any input distribution is compatible with the same posterior. Without p(x) we cannot get p(x,y) or p(x\mid y), and so we cannot generate inputs.