Every classifier covered throughout this hub โ from the Perceptron through CNNs and Transformers used for classification โ is a discriminative model. This category shifts to an entirely different family: generative models, which don't just tell classes apart โ they learn to produce new data resembling what they were trained on.
The Core Distinction
| Discriminative | Generative | |
|---|---|---|
| What it learns | A decision boundary between classes, given input \(x\) | The underlying data distribution itself |
| Can it generate new samples? | No โ it only classifies existing inputs | Yes โ sampling from the learned distribution produces new, plausible data |
| Examples covered so far | Logistic regression, every CNN/Transformer classifier | Autoencoders, VAEs, GANs (this category); diffusion models (next category) |
A Concrete Illustration
A discriminative image classifier learns to answer "is this a picture of a cat or a dog?" โ it needs only enough information to draw a boundary between the two classes, nothing more. A generative model trained on the same images learns something considerably harder: enough about what cats and dogs actually look like that it could, in principle, produce a brand new, never-before-seen image that plausibly looks like a cat or a dog.
Why Generative Modeling Is a Fundamentally Harder Problem
Discriminative models only need to capture whatever information separates classes โ details irrelevant to the decision boundary can be safely ignored. Generative models must capture much more of the data's actual structure and variation, since producing a convincing new sample requires modeling the full richness of what real data looks like, not just what distinguishes categories.
Code โ The Conceptual Difference
import torch.nn as nn
# Discriminative: maps an input DIRECTLY to a class prediction
discriminative_model = nn.Sequential(
nn.Conv2d(3, 32, 3), nn.ReLU(), nn.Flatten(), nn.Linear(32*30*30, 2) # cat vs dog
)
# Generative: maps RANDOM NOISE into a plausible new image
generative_model = nn.Sequential(
nn.Linear(100, 256), nn.ReLU(), nn.Linear(256, 3*64*64), nn.Tanh()
)
# Given a random noise vector as input, this network's job is to output
# something that LOOKS LIKE a real image -- a completely different task
Common Mistakes
- Assuming a generative model is always "more powerful" or strictly a superset of what a discriminative model can do โ for a task that only needs classification, a discriminative model is typically simpler, more data-efficient, and more directly optimized for that specific goal.
- Confusing "generative AI" as a marketing term with this precise technical distinction โ the term is used loosely in industry to describe systems that produce novel content (text, images), but the underlying technical definition here (modeling \(P(x)\) rather than \(P(y\mid x)\)) is more specific and precise.
Interview Relevance
Q: "Why is training a good generative model generally considered a harder problem than training a good discriminative classifier for the same data?" A discriminative model only needs to learn whatever information separates classes from each other, discarding everything else as irrelevant. A generative model must capture the data's full underlying distribution well enough to produce convincing new samples โ a substantially richer, harder modeling target than just finding a decision boundary.
Practice Question
Is a model trained to detect spam email discriminative or generative? What about a model trained to write new, realistic-looking emails?