What Are Generative vs Discriminative Models?
Generative models learn a distribution over data, such as p(x), a joint distribution p(x, y), or a distribution over data conditioned on a prompt or label. Discriminative models learn to predict a target from an input, either by estimating p(y | x) or by learning a decision rule directly. A generative model can classify emails, and a discriminative model can predict a number, so the visible output alone does not tell you which approach was used.

Start with the notation: x is an observed example, such as an email or its extracted features, and y is the target, such as spam or not spam. The joint probability p(x, y) describes how often that example and class occur together. The conditional probability p(y | x) answers a different question: given this example, how likely is each class? A spam filter can return the same answer using either approach.
| Question | Generative approach | Discriminative approach |
|---|---|---|
| What does it learn? | A distribution over observations, possibly conditional on a label or prompt, or a joint distribution over observations and labels. | A conditional distribution over targets, a score for each target, or a direct prediction rule. |
| How can it classify? | Compare class priors multiplied by class-conditional likelihoods, then normalise if probabilities are needed. | Evaluate the learned scores or probabilities and apply a decision rule. |
| What can it return? | Text, images, audio, simulations, synthetic features, or a class prediction, depending on the model. | A class, a score, a numeric prediction, or structured predictions such as object boxes and labels. |
| What are common examples? | Naive Bayes, GPT and Llama language models, variational autoencoders, GANs, and diffusion models. | Logistic regression, standard support vector machines, and random forests trained for classification or regression. |
The statistical meaning of generative model is broader than the product category Generative AI. A Naive Bayes spam filter is generative because it models how features occur within each class. Its samples might be pairs of zeros and ones, with no readable email attached. A prompt-based image application is generative because the model learns to produce image samples consistent with its conditioning input.
How Do Generative and Discriminative Models Learn?
Generative learning: Estimate how observations arise
A supervised generative classifier can factor its joint model as p(x, y) = p(y) p(x | y). It learns the class prior p(y) and a model for the features within each class, p(x | y). To sample from that model, draw a label from the prior, then draw features from the selected class distribution. To classify an observed example, reverse the direction of inference with Bayes' rule: p(y | x) = p(x | y) p(y) / p(x).
Modern content generators often learn p(x) or a conditional distribution p(x | c), where c could be a caption, a class, or a prompt. Here x is the content being generated. The conditioning variable is supplied to guide the output; it need not itself be modelled. In a text completion system, for example, the prompt is known and the continuation is sampled.
Different families of generative models implement this idea differently. An autoregressive language model multiplies token probabilities to assign a probability to a sequence. A variational autoencoder learns a decoder from latent variables to observations and uses a training objective that lower-bounds the log likelihood. A diffusion model learns to reverse a noise process; a common training objective asks it to predict the noise added to a training example at a chosen noise level. A GAN learns a sampler through competition with a discriminator and need not provide an evaluable probability density. A GAN's discriminator is trained to distinguish real examples from generated ones, while the generator is trained to produce samples that the discriminator scores as real.
Discriminative learning: Estimate the target or learn a decision rule
Binary logistic regression computes z = w·x + b and estimates the positive-class probability as 1 / (1 + exp(-z)). The weights are fitted from labelled examples by minimising binary cross-entropy, often with regularisation. Cross-entropy penalises the model for giving low probability to the observed label. The model never has to estimate how often a particular input occurs.
A standard support vector machine also learns from labelled examples, but its raw score is a signed margin rather than a probability. Its training objective rewards separation between classes and penalises margin violations. For a linear classifier, the decision boundary is the set of inputs where the score reaches the chosen threshold. With regression, the analogous task is to predict a target value rather than choose a side of a class boundary. Ordinary least squares, for example, fits a prediction rule by minimising squared residuals.
Worked Example: How Does a Generative Model Classify Spam?
Suppose a toy filter observes two binary features: whether an email contains the word offer and whether it contains a link. The training set has 40 spam emails and 60 legitimate emails. Among the spam emails, 30 contain offer and 20 contain a link. Among the legitimate emails, 6 contain offer and 12 contain a link. A new email contains both. What probability does the model assign to spam?

- Estimate the class priors. The spam prior is
40 / 100 = 0.40and the legitimate prior is60 / 100 = 0.60. - Estimate feature probabilities within each class. For spam, the probabilities are
30 / 40 = 0.75forofferand20 / 40 = 0.50for a link. For legitimate email, they are6 / 60 = 0.10and12 / 60 = 0.20. - Compute joint scores. Bernoulli Naive Bayes assumes the binary features are independent given the class. For spam the joint score is
0.40 × 0.75 × 0.50 = 0.150. For legitimate email it is0.60 × 0.10 × 0.20 = 0.012. - Normalise across classes. The probability of the observed feature pair under the fitted model is
0.150 + 0.012 = 0.162. Hencep(spam | x) = 0.150 / 0.162 ≈ 0.926. At a threshold of0.5, the filter predicts spam.
The independence assumption applies within each class. Emails containing offer may be more likely to contain a link even after you know they are spam. If so, multiplying the separate probabilities misestimates how often the features occur together. That can make the reported probabilities unreliable even when the predicted labels are useful. If a feature is absent, the Bernoulli model uses 1 - p(feature present | class) for that feature instead.
The example also separates estimation from action. A filter that sends messages to a review folder can use a different threshold from one that discards them. Choose the threshold on validation data based on the cost of each mistake. The computed posterior is an estimate under the fitted model; it does not establish that roughly 92.6 percent of real emails with these features are spam.
How to Compare Naive Bayes and Logistic Regression in Python
Install numpy and scikit-learn to run this example. Each row represents a feature pattern, and the two count columns specify how many training examples with that pattern belong to each class. Expanding those counts gives both classifiers the same 100 examples. Naive Bayes fits feature frequencies within each class; logistic regression fits its weights directly from the relationship between the feature rows and their labels.
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.naive_bayes import BernoulliNB
# Feature columns: contains "offer", contains a link
patterns = np.array([[1, 1], [1, 0], [0, 1], [0, 0]])
spam_counts = np.array([16, 14, 4, 6])
legit_counts = np.array([2, 4, 10, 44])
X = np.vstack([
np.repeat(patterns, spam_counts, axis=0),
np.repeat(patterns, legit_counts, axis=0),
])
y = np.array([1] * spam_counts.sum() + [0] * legit_counts.sum())
email = np.array([[1, 1]])
models = {
"Bernoulli Naive Bayes": BernoulliNB(alpha=0.0, force_alpha=True),
"Logistic regression": LogisticRegression(),
}
for name, model in models.items():
model.fit(X, y)
spam_column = list(model.classes_).index(1)
probability = model.predict_proba(email)[0, spam_column]
print(f"{name}: P(spam | email) = {probability:.3f}")
bayes = models["Bernoulli Naive Bayes"]
print("P(feature present | spam):", np.exp(bayes.feature_log_prob_[1]))
Naive Bayes prints 0.926, and its fitted spam feature probabilities are [0.75, 0.50]. The first 18 examples of the pattern with both features include 16 spam and 2 legitimate emails across the two classes, so the empirical spam fraction for this pattern is 16 / 18 ≈ 0.889. The Naive Bayes estimate differs because it multiplies marginal feature probabilities within each class instead of directly counting the joint feature pattern. Logistic regression uses the labels to fit an additive log-odds model with regularisation by default.
We disable smoothing to reproduce the arithmetic by hand. Real datasets can have features that never occur in a particular class. Without smoothing, one such feature can reduce that class's likelihood to zero. Additive smoothing is a common way to avoid this. This script demonstrates the mechanics of fitting and inference; since the example email has a feature pattern seen during training, its printed probabilities do not measure performance on unseen emails.
Generative AI vs Traditional AI: What Changes in Practice?
Traditional AI is a broad term that includes rule-based systems, search, and machine learning. In the comparison with GenAI, it often refers to conventional predictive ML: train a model to estimate demand, predict loan default, or detect defects. Traditional ML also includes generative methods such as Gaussian mixture models and unsupervised methods such as clustering. The distinction is more useful when you compare the objective, training signal, and output of a specific system.
| Dimension | Conventional predictive ML | Modern content generation |
|---|---|---|
| Product goal | Estimate a known target, such as next-day demand or defect probability. | Produce an artefact, such as an answer, image, code patch, or music clip. |
| Training signal | Often a measured outcome or human-provided label; some methods learn without labels. | Often self-supervision at pretraining scale, sometimes combined with paired data, demonstrations, or preference signals. |
| Output contract | Often a predefined label set, score, numeric value, or structured prediction. | Often many valid outputs for the same input; an application may still require a fixed schema. |
| Examples | Linear regression for demand, a decision tree for triage, or an SVM for document classification. | GPT or Llama for text and code, DALL-E or Stable Diffusion for images, or MusicGen for music. |
To see how pretraining differs from inference, consider a language model trained on the bus is late. After tokenization, the training text supplies both the prefixes and the next-token targets. No annotator has to label the next token. For token IDs t1, ..., tT, the autoregressive objective minimises -sum(log p(ti | t1, ..., t(i-1))), with the sum over token positions. A causal attention mask stops each prediction from seeing future tokens.
At inference time, the model conditions on the prompt, selects a next token, appends it to the sequence, and repeats until a stop condition is reached. A single step resembles multiclass classification over a fixed vocabulary, while the sequence of steps defines a generative model of complete outputs. A language model can also be prompted to return one label, and a modern vision detector can return boxes and classes. Model age, neural network size, and output formatting are poor substitutes for understanding the training objective.
How Do You Choose and Evaluate the Right Approach?
Start with what the system must deliver. If a warehouse needs tomorrow's demand per item, train a forecasting baseline and evaluate it on later dates than those used for training. If the warehouse needs a written summary of stock issues, a language model can draft the summary from validated inventory records. A single application can use both: a forecasting model supplies the numbers and a generator expresses them in sentences. Keep the source numbers available for checking the summary.
For classification, select metrics based on the errors that matter. A rare defect detector can achieve high accuracy by predicting that almost every item is normal. Precision tells you what fraction of flagged items are defects, while recall tells you what fraction of all defects were flagged. F1 summarises their balance, but the decision threshold should reflect the real cost of false alarms and missed defects. For regression, mean absolute error reports a typical absolute error in target units, while root mean squared error gives large misses more weight.
For a generator, define what a valid output must preserve and what may vary. In a support reply, phrasing may vary, while policy details and account facts must remain correct. Use automated checks for properties such as output schema and required fields, and assess factual consistency against the supplied records. Human reviewers can judge relevance, coherence, and whether the response resolves the request. A low next-token loss measures predictive fit on text; it does not establish factual accuracy or task success. The chapter on LLM evaluation and hallucination explains how to test those failure modes.
For data augmentation or simulation, evaluate the downstream result with held-out real data. For example, you might generate additional product-defect images for training. Compare the same detector trained with and without the synthetic images, using the same test set of real photos. Check whether performance improves for the rare defect classes you intended to help. Synthetic examples that look convincing can still omit the edge cases that determine whether the detector works.
Key Takeaways
- Generative models learn how data is distributed, sometimes conditioned on a prompt or label.
- Discriminative models learn a target prediction rule, a score, or a conditional distribution over targets.
- Naive Bayes combines class priors with feature likelihoods to classify; logistic regression estimates class probabilities directly.
- Autoregressive language models build a distribution over sequences from next-token probabilities.
- Traditional ML includes generative methods, and modern AI still uses discriminative models for tasks with predefined targets.
- Evaluate predictions against held-out targets and evaluate generated outputs against task-specific requirements.
Frequently Asked Questions
Is every model that outputs a probability generative?
No. Logistic regression outputs a probability for a target class given an input, without learning how the input features are distributed. Naive Bayes can return the same kind of class probability by modelling feature probabilities within each class and applying Bayes' rule. The distinction comes from what the model learns.
Why is Naive Bayes generative if it only predicts a label?
Naive Bayes learns a class prior and a distribution over features within each class. You can use those distributions to sample a class and then generate a feature vector. During classification, you instead observe the feature vector and infer its class. Both operations use the same fitted joint model.
Does generative AI always train on unlabelled data?
No. A language model can learn next-token prediction from raw text because the text supplies its own targets. Other systems use paired examples such as images and captions, human demonstrations, or preference judgements. A single model may use different kinds of supervision at different stages of training.
Can an LLM replace a discriminative classifier?
An LLM can return labels from a predefined set, and this can be useful when you have few examples or need a quick prototype. Compare it with a dedicated classifier on the same held-out inputs. Measure the errors that matter, invalid outputs, response time, and cost before deciding which system to deploy.
Which approach is better when training data is limited?
There is no universal winner. A simple generative classifier can work with fewer labels when its assumptions describe the data well. If those assumptions fail, its predictions can suffer. Test both approaches when practical, use validation data to tune them, and keep the final test set separate from model selection.