๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #290

Generative vs Discriminative Models

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

\[ \text{Discriminative: learn } P(y \mid x) \qquad \text{Generative: learn } P(x) \text{ or } P(x, y) \]
DiscriminativeGenerative
What it learnsA decision boundary between classes, given input \(x\)The underlying data distribution itself
Can it generate new samples?No โ€” it only classifies existing inputsYes โ€” sampling from the learned distribution produces new, plausible data
Examples covered so farLogistic regression, every CNN/Transformer classifierAutoencoders, 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?

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Generative vs Discriminative Models โ€“ FAQs

Quick answers about learning Generative vs Discriminative Models in Deep Learning.

This free note from CodingNow 2.0 explains Generative vs Discriminative Models in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Generative vs Discriminative Models, is 100% free with no signup required.
With focused practice, most students grasp Generative vs Discriminative Models in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now