0% completed
Generative vs Discriminative Models
On This Page
Part 1: Two Jobs for the Same Input
Part 2: How a Discriminative Model Works
Part 3: How a Generative Model Works
Part 4: Why Creating Is the Harder Job
Part 5: Why Creating Is Also More Useful
Part 6: Most Products Use Both
Part 7: What This Changes for an Engineer
Common Mistakes
Key Takeaways
Most AI models inside products do one of two jobs. They either sort or create.
A sorting model puts an input into a category. Take a support message that says, "I was charged twice for my order." A sorting model reads the message and picks a label, such as "billing." It chooses from a short list that the team set in advance, such as "billing," "shipping," and "account." A spam filter works the same way and picks "spam" or "not spam." A fraud check is similar, but it gives each payment a risk score between 0 and 1.
A model that creates produces something new. Given the same message, it can write a reply to the customer. That reply is not on any list, because it did not exist until the model wrote it.
A model that sorts is called a discriminative model, and a model that creates is called a generative model. In statistics, the word "generative" also has a narrower meaning: a model of how the data itself is produced. In that sense, some simple classifiers, such as naive Bayes spam filters, are generative even though they only sort. This course uses the practical meaning: a generative model creates new content.
Knowing what kind of feature you need tells you a lot about its cost, speed, and how to test it. Creating is harder, but it is also more useful.
Part 1: Two Jobs for the Same Input
The two kinds of models learn different things during training.
A discriminative model learns the differences between categories. For example, it learns what makes a billing message different from a shipping message. Its output is always a label or a score from a predefined range.
A generative model learns what the data itself looks like, so it can produce new examples of that data. Its output is new content, such as a sentence, a block of code, or an image.
The diagram below sends the same support message to both kinds of models.
Look at the two outputs. The discriminative model returns a single label and a confidence score of 0.92, indicating how sure the model is. The generative model returns a full paragraph that did not exist before.
Part 2: How a Discriminative Model Works
A discriminative model answers one question: which label fits this input best? A discriminative model that picks labels is also called a classifier.
The model learns to answer from examples. During training, it sees many messages people have already labeled, such as billing messages and shipping messages. From these examples, it learns where the line falls between labels.
You can picture this as a line drawn on a map. Messages about charges and refunds land on one side, and messages about late packages land on the other. The model does not need to understand everything in a message. It only needs to tell which side of the line the message falls on.
Many familiar features use discriminative models:
- A spam filter chooses between "spam" and "not spam."
- A fraud check gives each payment a risk score between 0 and 1.
- A sentiment model labels a review as positive, neutral, or negative.
- An image classifier names the main object in a photo, such as "dog" or "car."
These models are usually small, fast, and cheap to run. Their results are also easy to measure. With a set of labeled test examples, you can count how often the model picks the right label.
Part 3: How a Generative Model Works
A generative model answers a different question: what would a good example look like here?
To answer it, the model must learn the data's patterns. For text, that means grammar, facts, tone, and the usual order of ideas. This is far more to learn than the line between two labels.
Most generative models build their output one small piece at a time. A large language model, or LLM, writes text by predicting the next piece of text, based on everything that came before it. It adds that piece, predicts the next one, and repeats until the answer is complete. Image models use a different method, but they also build their output over many small steps.
This is how a generative model can write a reply it has never seen. It does not copy a stored answer. It produces a new sequence that fits the patterns it learned.
Part 4: Why Creating Is the Harder Job
The main reason is the number of possible answers. In the support example, the discriminative model picks one of three labels. Even a random guess is right 1 out of 3 times.
A generative model faces a far larger set of choices. Suppose a reply is 100 words long, and each word can be any of 50,000 common words. The number of possible replies is then a number with about 470 digits. Almost all of these replies are nonsense. The model must find one of the few that make sense, sound right, and are true.
The diagram below compares the two sets of possible answers.
Creating is harder in three other ways as well:
- Errors can grow. Each new word depends on the words before it. One wrong word early in a reply can push the rest of the reply in the wrong direction.
- There is no single right answer. Many different replies can be acceptable, so you cannot simply compare the output with one correct label.
- A fluent answer is not always a true one. A generated reply can read well and still contain a false fact. Later lessons call this a hallucination and show how to reduce it.
Part 5: Why Creating Is Also More Useful
The harder job brings a large benefit. A generative model can produce whatever a task needs, such as a reply, a summary, a translation, a test, or a plan. It isn't limited to a list of labels someone chose in advance.
A generative model can even do a sorting job. You can ask an LLM, "Is this message about billing, shipping, or account? Answer with one word." It will usually return the right label, even though it was never trained on your labels. This flexibility is a major reason generative models spread so quickly.
The flexibility has a cost, though. An LLM call is much slower and more expensive than a small classifier. Its answers can also change from one call to the next. For a high-volume task with a fixed set of answers, a small discriminative model is often the better choice.
Part 6: Most Products Use Both
Real features rarely use only one kind of model. They combine the two, and each model does the job it does best.
The diagram below shows one support feature that uses both kinds of models on the same message.
Step 1: Route the message. A discriminative model labels the message "billing" and also marks it as urgent. This step is fast and cheap, and it assigns ownership of the ticket to the right team.
Step 2: Draft the reply. A generative model writes a reply, using the label and the customer's order details.
Step 3: Check the draft. A second discriminative model gives the draft a risk score. A high score means the draft may contain a problem, such as a promise the company cannot keep. Those drafts go to a person before they are sent.
Notice where each kind of model sits. The generative model is in the middle, where new text is needed. The discriminative models sit at the start and end, where the job is to sort or check.
Part 7: What This Changes for an Engineer
When you plan an AI feature, first ask what its output looks like. The answer often tells you which kind of model to use.
| If the output is | Use | Because |
|---|---|---|
| A label from a fixed list | A discriminative model | It is fast, cheap, and easy to measure |
| A score, such as a risk level | A discriminative model | The score can feed a clear rule |
| New text, code, or an image | A generative model | No fixed list holds the answer |
| A label, but with no training data yet | A generative model, for now | It can label from instructions alone |
The model type also changes how you test the feature. For a discriminative model, you measure accuracy on labeled examples. For a generative model, there is no single correct output, so you need a set of test cases and a way to score open-ended answers. The later lesson "Evals: Knowing Your Feature Works" shows how teams do this.
Common Mistakes
Mistake 1: Using an LLM for every step. An LLM can label messages, but at high volume, a small classifier does the same job faster and more cheaply, with more consistent results.
Mistake 2: Judging generated text only by how it reads. A fluent answer can still be wrong. Check the facts, not only the tone and grammar.
Mistake 3: Testing a generative feature like a classifier. A generative feature rarely has one correct output to compare against. Plan how you will score open-ended answers before launch.
Key Takeaways
- A discriminative model sorts, and a generative model creates. One picks an answer from a fixed set, and the other produces new content.
- Creating is harder because there are so many possible answers. The model must build one good answer piece by piece, and an early error can grow.
- Creating is more useful because it is flexible. A generative model can write, summarize, translate, and even sort.
- Real features use both. Discriminative models route and check, and a generative model writes in between.
The next lesson, How We Got Here, follows AI from hand-written rules to today's generative models. It shows what each step made possible and which problem led the field to the next step.
Reading Progress
0%
On This Page
Part 1: Two Jobs for the Same Input
Part 2: How a Discriminative Model Works
Part 3: How a Generative Model Works
Part 4: Why Creating Is the Harder Job
Part 5: Why Creating Is Also More Useful
Part 6: Most Products Use Both
Part 7: What This Changes for an Engineer
Common Mistakes
Key Takeaways