A generative model learns the distribution of the training data well enough to draw new samples from it. Three families dominate image generation: variational autoencoders (VAEs), generative adversarial networks (GANs) and diffusion models. They answer the same question, how do you train a network to turn noise into data, with three different objectives, and the differences show up in sample quality, training stability, sampling speed and whether you get a likelihood.

One network draws fakes, the other spots them, and both keep getting better. Image: Mtanti, CC BY-SA 4.0, via Wikimedia Commons.
Mental Model
- A likelihood-based model defines or bounds and is trained by maximizing it. An implicit model only gives samples, and needs a different training signal.
- A VAE compresses data to a latent code through an encoder and decodes it back. A KL term keeps the latent space close to a simple prior so that sampling from the prior produces plausible outputs.
- A GAN trains a generator against a discriminator. There is no likelihood, only a game, which is why it is fast to sample from and hard to train.
- A diffusion model learns to undo a fixed noising process one small step at a time. Training is plain regression, and sampling takes many network evaluations.
- Guidance trades diversity for fidelity to a condition such as a text prompt.
1. Likelihood Versus Implicit Models
Maximum likelihood fits to the data. Autoregressive models and normalizing flows do this exactly. VAEs and diffusion models optimize a lower bound on because the exact value involves an integral over latent variables that cannot be computed. GANs skip the density altogether: the generator is a function that maps noise to samples, and you can sample from it but not evaluate how likely a given image is. Implicit models avoid the compromises that come with a likelihood (such as blurry averages), but they need an adversarial or other indirect objective.
2. Variational Autoencoders
The encoder outputs the parameters of , the decoder models , and the prior is . Training maximizes the evidence lower bound (ELBO), from Kingma and Welling (2013):
The first term is the reconstruction quality, the second regularizes the code. For a diagonal Gaussian against the standard normal the KL has a closed form:
Worked example
For a single latent dimension with and : . A Monte Carlo estimate over a million samples, taking the mean of , gives 0.818 as well.
Sampling from is a random step, and gradients cannot flow through it. The reparameterization trick moves the randomness into a separate variable:
Now is a deterministic, differentiable function of and plus fixed noise. With a Gaussian decoder the reconstruction term is a squared error, and that averaging is the usual explanation for blurry VAE samples. A failure mode to know is posterior collapse: a decoder that is strong on its own ignores , and the KL goes to zero. Weighting the KL by a factor (the -VAE) controls the trade-off between reconstruction and a well-structured latent space.
3. GANs
Goodfellow et al. (2014) set up a two-player game between a generator and a discriminator that outputs the probability that its input is real:
For a fixed generator the best discriminator is . Plugging it in turns the generator’s objective into , which is minimized when . In practice the generator uses the non-saturating loss , because early in training wins easily and the original term gives almost no gradient.
The theory assumes is optimal at every step, which never holds, and training is a moving target. Common problems are oscillation and mode collapse, where finds a few outputs that fool and produces little variety. Wasserstein GANs (Arjovsky et al., 2017) replace the loss with an earth-mover distance estimate that gives more informative gradients when the two distributions barely overlap.
4. Diffusion Models
Denoising diffusion probabilistic models (Ho et al., 2020) define a fixed forward process that adds a little Gaussian noise at each of steps:
With and you can jump to any step in one go:
The reverse process is learned. A network is trained to predict the noise that was added, with a simple loss:
A training step picks a random , noises an image with the closed form, and regresses the noise. Sampling starts from and repeats
for , with fresh noise at every step but the last. Ho et al. use a linear schedule from to with .
import numpy as np
T = 1000
betas = np.linspace(1e-4, 0.02, T)
ab = np.cumprod(1 - betas) # alpha_bar
print(ab[499], ab[-1]) # 0.0786, 4.0e-05
rng = np.random.default_rng(0)
x = np.ones(20000) # 20000 chains starting at x0 = 1
for t in range(500):
x = np.sqrt(1 - betas[t]) * x + np.sqrt(betas[t]) * rng.normal(size=x.size)
print(x.mean(), np.sqrt(ab[499])) # about 0.27 vs 0.28
print(x.std(), np.sqrt(1 - ab[499])) # about 0.96 vs 0.96By the signal coefficient is about 0.006, so is nearly pure noise and starting the reverse process from a standard normal is justified. Running 500 noising steps one at a time reproduces the closed-form mean and standard deviation, which is what makes cheap training possible.
Classifier-Free Guidance
For conditional generation (a text prompt ), train one network with the condition randomly dropped, for example 10% of the time, so it learns both and an unconditional . At sampling time extrapolate away from the unconditional prediction (Ho and Salimans, 2022):
Scale is the plain conditional model, larger values follow the prompt more closely and give less varied images, and values that are too high produce oversaturated, distorted results. It costs two network evaluations per step. Latent diffusion (Rombach et al., 2022) runs the whole process in the latent space of an autoencoder rather than in pixel space, which makes high-resolution generation affordable.
5. Comparison
| Model | Training objective | Sampling | Likelihood | Typical weakness |
|---|---|---|---|---|
| VAE | ELBO (reconstruction plus KL) | One decoder pass | Lower bound | Blurry samples, posterior collapse |
| GAN | Adversarial minimax game | One generator pass | None | Mode collapse, unstable training |
| Diffusion | Noise-prediction MSE | Tens to 1000 network passes per image | Bound, rarely used | Slow sampling, needs many steps or distillation |
Related
- MPL 09: VAEs, MPL 10: GANs and MPL 12: Diffusion, the lectures for the three families
- Embeddings, for the latent spaces these models learn and the CLIP encoders used for prompts
- Attention and Transformers, the backbone of modern text-conditioned diffusion models
- Convolutional Networks, the building block of the original U-Net denoisers and GAN generators
- Generalization and Regularization, for why the KL term acts as a regularizer
- Neural Style Transfer, an earlier, optimization-based way to generate images from CNN features