How can a model create something it has never stored?
A generative model studies many examples and adjusts its internal parameters so that common structures become more likely than implausible ones. During generation, it uses those learned patterns plus a starting signal—often a random value, a prompt, a class label, an image, or an unfinished sequence—to construct a new sample.
By the end of this lesson, you will be able to explain what a learned data distribution means, what a latent representation stores, why randomness creates variety, how conditioning gives control, and why training and generation are separate processes.
How Generative Models Learn in Simple Words
Imagine a master musician who has listened to thousands of jazz songs. They haven’t memorized every note by rote; instead, they have learned the probability space of jazz—which chord progressions usually follow one another, where surprises sound pleasant, and how tempo shapes emotion. When given a theme (condition) and a burst of spontaneous improvisation (random seed), they compose a fresh, original solo!
Learn Distribution
Map which features occur together
Compact Latent Space
Organize concepts into hidden coordinates
Sample with Seed
Randomness converts odds into a unique draft
Guide with Condition
Prompts steer probability towards user intent
Figure 1 — Learning mode builds the model; generation mode reuses it
Training measures an error and sends a parameter update back to the learned representation. Generation starts from a condition plus sampled randomness and reuses the same trained model without updating it.
The training lane sends a dataset into a learned representation or distribution, produces a reconstruction, measures loss, and feeds a parameter update back into the model. A dotted bridge leads to the generation lane, where a condition and sampled latent value or noise enter the same trained model with fixed parameters to produce a new sample.
Two different questions: deciding and generating
Suppose a dataset contains photographs of forests, coasts, and cities. A discriminative model receives one photograph and asks which class it belongs to. A generative model asks what combinations of colour, texture, shape, and layout would look plausible among those photographs.
| Model viewpoint | Question | Input | Output |
|---|---|---|---|
| Discriminative | “Which class does this example belong to?” | An existing photograph | Forest, coast, or city |
| Generative | “What examples could plausibly come from this data?” | A starting signal and optional guidance | A newly constructed scene |
What “learning the data distribution” means
A distribution describes which outcomes are possible and how likely they are. For a simple dataset, it may say that 5 of 10 scenes are forests, 3 are coasts, and 2 are cities. A useful image model must learn much richer relationships: where sky usually appears, how water reflects light, which edges form buildings, and which combinations rarely occur.
Tiny probability estimate
p̂(category) = count(category) / N
Here count(category) comes from the training data and N = 10 is the total number of examples. Therefore p̂(forest) = 5/10 = 0.50, p̂(coast) = 3/10 = 0.30, and p̂(city) = 2/10 = 0.20. The hat on p̂ means this is an estimate learned from available data, not a perfect description of the real world.
Representation and latent-space intuition
A representation is an internal numerical description that preserves useful features. A latent space is a representation space whose coordinates are learned rather than directly supplied as labels. One direction might respond to open water, another to brightness, and another to dense vertical edges—even when nobody named those features during training.
“Latent” means hidden. A point in latent space is not the address of a saved picture. It is a compact set of feature values that a decoder or generator can transform into an output. Nearby points often produce related outputs because their feature values are similar.
Figure 2 — A latent space stores useful relationships, not file locations
Nearby points represent examples with similar learned features. A sampled point between known examples can decode into a related new example.
A two-dimensional latent space contains nearby green forest examples, blue coast examples, and amber city examples. Horizontal movement means more water-like and vertical movement means brighter or more open. A sampled latent point z near the coast cluster follows a curved decoding arrow to a newly constructed coast scene.
Randomness, sampling, and conditioning
Randomness supplies variety
A random number, noise vector, or random token choice lets repeated runs reach different plausible regions instead of returning one fixed result.
Sampling makes a choice
Sampling uses the learned probabilities to select a next token, latent point, category, or denoising path.
Conditioning supplies direction
A prompt, class, reference image, mask, or other signal changes which outputs are likely without removing all variety.
Worked example: one random value, two distributions
| Value | Value used | Where it came from | Role |
|---|---|---|---|
| Unconditional probabilities | forest 0.50, coast 0.30, city 0.20 | Calculated from 10 training examples | Base learned distribution |
| Condition | sunset | Chosen by the developer or user | Guides the requested output |
| Conditional probabilities | forest 0.20, coast 0.70, city 0.10 | Toy values representing learned sunset relationships | Distribution after guidance |
| Random draw r | 0.35 | Normally produced by a random-number generator | Selects one probability interval |
Without a condition
Intervals: forest [0.00, 0.50), coast [0.50, 0.80), city [0.80, 1.00).
Because 0.35 lies in [0.00, 0.50), the calculated choice is forest.
Conditioned on “sunset”
Intervals: forest [0.00, 0.20), coast [0.20, 0.90), city [0.90, 1.00).
The same 0.35 now lies in [0.20, 0.90), so the calculated choice becomes coast.
Reproduce the sampling calculation in Python
The function adds probabilities from left to right. The first cumulative interval containing random_value determines the result.
categories = ["forest", "coast", "city"]
# Calculated from 10 training examples: 5 forest, 3 coast, 2 city
unconditional = [0.50, 0.30, 0.20]
# Learned for the developer-supplied condition "sunset"
sunset_condition = [0.20, 0.70, 0.10]
def choose_category(random_value, probabilities):
running_total = 0.0
for category, probability in zip(categories, probabilities):
running_total += probability
if random_value < running_total:
return category
r = 0.35 # normally supplied by a random-number generator
print("Unconditional sample:", choose_category(r, unconditional)) # forest
print("Sunset condition sample:", choose_category(r, sunset_condition)) # coastInteractive Sampling & Conditioning Simulator
Drag the random value slider r in [0, 1) or switch conditions to see how samples emerge!
r = 0.42The random seed 0.42 landed in the Forest cumulative interval. Changing condition shifts interval widths without retraining the weights!
What can go wrong?
The data distribution is incomplete
A model trained mostly on daylight photographs will not automatically learn reliable night scenes.
Likelihood is not truth
A plausible sentence or image can still contain a factual, physical, or social error.
Conditioning is influence, not a guarantee
A prompt can guide the distribution without forcing every detail to appear correctly.
Novel-looking output may still be too similar
Duplicates, small datasets, and overfitting can cause memorization or privacy leakage.
Summary / Key Takeaways
- A generative model learns patterns that make some data examples more plausible than others.
- A discriminative model labels an existing example; a generative model can construct a new one.
- A representation stores useful numerical features, and a latent space is a learned hidden representation space.
- Sampling turns learned probabilities into one concrete choice; randomness allows multiple valid outputs.
- Conditioning changes the output distribution using a prompt, class, image, or other guiding signal.
- Training updates parameters from examples and an objective; generation reuses fixed trained parameters.
- Autoregressive, VAE, GAN, and diffusion models reach new samples through different mechanisms covered in later lessons.