Contents
Generative vs Discriminative Modelsand Bayes’ Theorem
The painter and the critic, from Bayes’ theorem to diffusion and flow matching
A tutorial companion to the video Machine Learning Interview #6: Generative vs Discriminative Models (and Bayes’ Theorem) PDF
01Introduction
1.1The question
“What is the difference between a generative and a discriminative model?” is one of the most common machine learning interview questions. Picture two people who both look at thousands of photos of cats and dogs. The first is a painter: she studies what cats look like and what dogs look like, so well that she could paint a brand-new cat that never existed. Shown a photo, she asks which of her two pictures it resembles more. The second is a critic: he never learns to paint, he only learns the differences, “pointy ears, short snout: cat”. Both can label a photo, but only the painter can create one. The painter is a generative model, the critic a discriminative model, and this tutorial turns the picture into formulas.
1.2Prerequisites and notation
Prerequisites. Basic probability (conditional probability, the product rule, the normal distribution), derivatives and the chain rule, vectors and matrices. Maximum likelihood and Bayes’ theorem are used throughout; the tutorial of episode 5 covers both in detail.
Notation. An input is x\in\mathbb R^D (an image, a document, a vector of measurements) and its label is y\in\{0,1\} or y\in\{1,\dots,C\}. \pi_c=p(y=c) is the prior probability of class c, p(x\mid y=c) the class-conditional density, p(y\mid x) the posterior. \mathcal N(x\mid\mu,\Sigma) is a Gaussian density with mean \mu and covariance \Sigma, \sigma(a)=1/(1+e^{-a}) the logistic (sigmoid) function, and \log the natural logarithm. For diffusion and flow matching, x_0 and x_1 denote the two ends of a path from noise to data; the conventions of each method are stated where they are used.
1.3A short history
The generative recipe, model how the evidence arises and invert with Bayes’ theorem, is as old as probability theory (Bayes and Price, 1763). Fisher (1936) classified three species of iris from four flower measurements with what we now call linear discriminant analysis, a generative classifier despite its name (Murphy, 2022, §9.1). Shannon (1948) generated “approximations to English” by sampling one letter or word at a time from statistics of real text, the first generative language models. Cox (1958) introduced logistic regression, the prototypical discriminative model, and Maron (1961) classified documents with what is now called naive Bayes, which later became the classic spam filter (Sahami et al., 1998). Vapnik argued that one should solve a classification problem directly rather than first solving the more general problem of modelling p(x\mid y) (Vapnik, 1998), an argument behind support vector machines (Cortes and Vapnik, 1995). Ng and Jordan (2002), presented at the NIPS conference in December 2001, showed that the truth is more interesting: each approach wins in its own regime. Since 2014 generative models have learned to create images, sound and text: generative adversarial networks (Goodfellow et al., 2014), variational autoencoders (Kingma and Welling, 2014), diffusion models (Sohl-Dickstein et al., 2015; Ho et al., 2020) and flow matching (Lipman et al., 2023; Liu et al., 2023).