A model that produces pairs of numbers, sentences or images can make every single sample look right and still be a poor model of the data. It may never produce whole regions of the distribution, it may copy training examples, and its fluent output may be false. This lesson defines a generative model, derives the autoregressive likelihood exactly, and explains at an introductory level what variational autoencoders, generative adversarial networks and diffusion models optimize. Their training objectives measure different things and are not interchangeable likelihood scores. A constructed distribution on two binary coordinates serves as the running example.
Key terms
Generative model
Definition A generative model specifies a probability distribution over observations, a probability mass function or density with parameters , or when it is conditioned on a prompt, a class or another input . It is fitted to training observations so that it approximates the unknown data distribution . Some generative models can evaluate for a given , some can only draw samples, and some can do both. A discriminative classifier, by contrast, models only the label given the input, , and says nothing about how the inputs themselves are distributed.
In plain words A generative model describes how observations vary, so it can produce new ones. Whether a sample is plausible is one question. Whether it is true, useful, original or permitted for a particular use are further questions, and the model’s probability calculations answer none of them.
Example The constructed target distribution of this lesson has two binary coordinates and with
The four probabilities add to . Each coordinate on its own is balanced, , but the two coordinates agree with probability . A sampler for this table produces frequencies that fluctuate around these probabilities. In independent draws the frequency of has standard deviation , so a simulation checks the sampler but never replaces the declared table.
Autoregressive factorization
Definition Order the coordinates of an observation as and write . Every outcome with positive probability satisfies
where the factor for is . The derivation is the multiplication rule applied repeatedly. It gives , and induction on gives the product. The identity holds for every distribution and every order of the coordinates. An autoregressive model parameterizes each conditional directly, for example with a decoder-only transformer. Because each conditional adds to over , the product is then automatically a valid joint distribution. For independent observations the likelihood is the product of their probabilities, so the log likelihood is the sum of over all observations and positions . Maximizing it is the same as minimizing the negative log likelihood. A reported average must say whether it is per observation, per token or per coordinate, because these denominators give different numbers. For continuous coordinates the factors are densities, and a density value is not the probability of one exact point.
In plain words A joint distribution can always be generated one coordinate at a time, each choice conditioned on the ones already made. That part is exact. The modeling work is in representing each conditional, and the chosen order changes how hard each conditional is to learn, even though a perfect model could use any order.
Example For the constructed table, draw with and then let equal with probability . This gives and , and the row follows the same way. Three independent constructed observations , and have probabilities , and , so
nats per two-coordinate observation, or about nats per coordinate. The rare observation contributes , more than twice the of each common one. A model that treats the coordinates as independent balanced bits gives every pair . Averaged over the target table, the expected negative log probability is about for the correct model and for the independent one. The independent model matches both single-coordinate distributions exactly and still misses the dependence between them.
Latent-variable model and variational autoencoder
Definition A latent-variable model introduces an unobserved variable with a prior distribution and a conditional distribution of the observation. Its distribution of observations is the marginal
with an integral in place of the sum when is continuous. Sampling draws from the prior and then from . A Gaussian mixture is an example with a discrete . A variational autoencoder, or VAE, is a latent-variable model with a continuous latent vector, usually with the standard normal prior , whose decoder is a neural network that outputs the parameters of . With such a decoder the marginal and the posterior generally have no closed form, so a second network, the encoder, outputs the parameters of an approximate posterior . Encoder and decoder are trained together by maximizing the evidence lower bound of the next card. Unlike an ordinary autoencoder, which maps each input to one code and back, a VAE defines a probability model, and it generates new observations by decoding draws from the prior.
In plain words The model explains the variation in the data through a hidden variable that it introduces itself. That variable is part of the model’s construction, not evidence of a real hidden cause in the system that produced the data. The encoder answers which latent values could have produced a given observation, and the decoder answers which observations a given latent value tends to produce.
Example Draw a balanced binary , set , and set with probability . Summing over gives and , and the other two pairs follow the same way, so this latent-variable model reproduces the constructed table exactly. The autoregressive construction of the previous card produces the same table without any latent variable, so fitting the data well does not identify the mechanism behind it.
Evidence lower bound
Definition For discrete distributions and on the same set, the Kullback-Leibler divergence is
with the sum over the values where . It is finite when wherever , it is never negative, it is exactly when , and it is not symmetric in and . Now take a latent-variable model with prior and likelihood , an observation with evidence , and posterior . For a distribution over the latent values that is positive only where the posterior is positive, the evidence lower bound is
and it satisfies the identity
with integrals and densities in place of sums when is continuous. The last divergence is never negative, so , with equality exactly when is the posterior. A VAE uses for each training observation and maximizes the sum of the ELBOs over and . The first term rewards reconstructions that the stated observation model finds probable, and the second keeps the approximate posterior close to the prior.
In plain words The log likelihood of a VAE is hard to compute, but the ELBO can be estimated from draws of , and it is never larger than the log likelihood. Raising it either improves the model or tightens the bound by bringing closer to the true posterior, and the gap is exactly the divergence between the two. An ELBO is a bound on a log likelihood, so its value cannot be ranked against a GAN loss or a diffusion training loss.
Example A separate constructed model has two latent states with prior probabilities each, and the observed event has probability in state and in state . The evidence is , and Bayes’ rule gives the posterior . Take the approximate posterior . The reconstruction term is and the prior divergence is , so
below the log evidence . The gap of about equals . Reversing the first divergence gives instead of , which shows the asymmetry.
Generative adversarial network and mode collapse
Definition A generative adversarial network, or GAN, pairs a generator , which maps a noise vector drawn from a fixed distribution to a synthetic observation , with a discriminator , which outputs a number in read as the probability that its input came from the training data. The original objective is the game with the value function
where the first expectation is over training observations and the second over the noise. It is trained by alternating gradient steps, the discriminator ascending and the generator descending, and in practice the generator often maximizes instead because that gives stronger gradients early in training. A standard GAN provides no normalized likelihood , and the value of its loss depends on the current discriminator. In an idealized analysis with unlimited capacity and exact optimization, the game is solved when the generator’s distribution equals , but finite networks trained by alternating steps need not reach that point. Mode collapse is the failure in which the generator produces only a limited part of the data distribution and misses other regions that carry substantial probability.
In plain words The generator learns by trying to fool a critic that is learning at the same time. A collapsed generator can produce samples that each look perfectly valid, so a few appealing samples cannot reveal the failure. Coverage has to be measured by comparing the distribution of many generated outputs with held-out data.
Example A generator for the constructed table that outputs and half the time each produces only valid, common pairs, yet never produces or , which together carry probability under the target. Five independent draws from the target itself contain no such pair with probability , so five samples often cannot tell the two apart. For draws that probability is , so counting over a large sample exposes the collapse. Read as a distribution, the collapsed generator gives probability to a held-out pair , so its log likelihood on data containing that pair is .
Diffusion model
Definition A diffusion model defines a forward process that adds Gaussian noise to a training observation over many steps and learns a reverse process that turns noise back into observations. In a common formulation the noisy version at step can be drawn directly as
where is drawn from independently of and the schedule decreases from near at the first step to near at the last step . A network is trained to predict the added noise by minimizing the average of over training observations, steps and noise draws. Sampling starts from pure noise drawn from and applies learned reverse steps one after another. The objective, schedule and sampler differ between formulations. This noise-prediction loss is related to a variational bound, but with its usual weighting it is not the model’s log likelihood, and its value depends on the schedule and the weighting.
In plain words Destroying data with noise is easy and needs no learning. The learned part runs the other way. From a noisy input and its noise level the network estimates what noise was added, and the sampler uses that estimate to take a step toward cleaner data. During generation neither the clean point nor the true noise is known, so repeatedly applying some smoothing filter is not a diffusion sampler.
Example Take the constructed clean point , the schedule value and the noise vector . Then and , so
If an oracle supplied the true noise, would recover exactly. A trained network only estimates the noise. The estimate gives , which misses the clean point by times the noise error . This is one forward noising step and its inversion, not the output of a trained diffusion model.
Check yourself
- A generator of binary pairs draws with probability . Given it sets with probability , and given it sets with probability . Find and and the likelihood of the two independent observations and . What is wrong with a generator that always emits the most probable pair?
Show the answer
By the autoregressive factorization, and . The likelihood of the two independent observations is
The other two pairs have and , and the four probabilities add to .
The most probable pair is . A generator that always emits it produces a valid and fairly common outcome every time, but it never produces the other three pairs, which carry probability . This is complete mode collapse. Read as a distribution it gives probability to the observation , so the likelihood of the two observations above under it is .
- In the two-state model of the ELBO card, take the approximate posterior equal to the prior, . Compute the ELBO and its gap to the log evidence. For which is the bound tight?
Show the answer
The prior divergence is because equals the prior. The reconstruction term is
so the ELBO is about . The log evidence is , so the gap is about . It equals the divergence from to the posterior, . The approximate posterior of the card gave the tighter value because it is closer to the posterior.
The bound is tight exactly when is the posterior . Then the reconstruction term is , the prior divergence is about , and the ELBO is , with gap .
- A team reports that viewers rated a gallery of samples from its image GAN as realistic, and that its training loss is lower than the training loss of a competing diffusion model. Which evaluation questions remain open, and is the loss comparison meaningful?
Show the answer
Realism ratings address sample fidelity only, and only for the samples shown. A gallery chosen by hand is not representative, so the samples should be drawn by a stated procedure and rated with a stated comparison set and uncertainty. Several separate questions remain open.
- Coverage. Does the generator produce the full variety of the data in the right proportions? Compare the distribution of many generated outputs with held-out data and look for missing regions, as with the diagonal-only generator, which never produces pairs that carry probability .
- Memorization. Does it reproduce particular training images? Search the training set for exact or near copies of generated images and compare with how close held-out images come. In a space with four possible outcomes repetition proves nothing, but for high-dimensional images a near copy of a training image is real evidence.
- Task usefulness. Do the outputs help the intended task, judged by a protocol fixed in advance? A realistic image can still carry a wrong label or unsafe details.
- Accuracy and permission. Whether generated content is factually correct, and whether the training data and outputs may be used, needs separate evidence that no generation metric supplies.
The loss comparison is not meaningful. A GAN loss depends on its own discriminator, and a diffusion loss is a weighted noise-prediction error under a particular schedule. The two numbers measure different quantities, so ranking them says nothing about which model is better. Both models have to be compared on a common, justified evaluation question.