1 What is generation, and what is a generative model?
Suppose we want an AI to learn how to generate images. At first, producing a single convincing image might seem like success.
But what if it produces exactly the same image every time? Or simply retrieves an image from a database? Even if the result looks completely real, would we say that the AI has learned to generate images?
Probably not.
So what is missing?
This question brings us to one of the fundamental ideas behind modern generative models. Let’s start here and explore what it means for an AI to generate an image.
1.1 What should a two-pixel generator reproduce?
Consider an image with two pixels. Each pixel is either black (\(0\)) or white (\(1\)), so the possible images are \(00\), \(01\), \(10\), and \(11\). The source produces only \(00\) and \(11\), each with probability \(1/2\). Write \(P\) for the source distribution and \(X\) for a random image drawn from it. A string such as \(00\) is one possible value of \(X\).
Compare three proposed programs.
| Program | Sampling procedure |
|---|---|
| A | Always output \(00\). |
| B | Flip a fair coin independently for each pixel. |
| C | Flip one fair coin and use its result for both pixels. |
Pause 1. Find the probability that each program assigns to each complete image. Which programs make each pixel black half the time? Which reproduces the source distribution?
For B, multiply the probabilities of the two independent coin flips. For C, each result of the single coin flip determines the entire image.
All three programs can produce \(00\). Their behavior differs across repeated runs. A always returns a valid image but omits \(11\). B gets each pixel’s frequency right but sometimes produces mixed images. C reproduces both the possible images and their frequencies. To distinguish the programs we need the probabilities of complete images, which capture the relationship between the pixels.
This gives a reason to describe generation using probability. Each run produces one image, and the program’s random choices determine the distribution of those images. If the program and source assign the same probabilities to all four images, they also assign the same probability to any event we can check on an image, such as whether its pixels agree. The distribution is the object we compare when the goal is to reproduce observable behavior.
1.2 Generation and generative models
A generative model specifies a probability distribution \(Q\) over complete outcomes. A sampler is a procedure whose output has that distribution. Generation is running the sampler to produce an outcome. For a discrete outcome space, the model can give probabilities in a table. A sampling procedure can also specify the distribution implicitly through the probabilities of its outputs.
For Program C, write \[ Z\sim\operatorname{Bernoulli}(1/2), \qquad X=G(Z)=(Z,Z). \]
Here \(Z\) is a fair bit and \(G\) copies it into both pixel positions. In general, if \(U\) collects a sampler’s random choices and \(G(U)\) is its output, the induced distribution assigns each event \(A\) the probability
\[ Q(A)=\Pr\bigl(G(U)\in A\bigr). \]
Pause 2. Replace \(G\) by \(G'(z)=(1-z,1-z)\), keeping the fair input bit. Does the output distribution change? What if the input bit equals \(1\) with probability \(3/4\)?
For each map, find which input gives \(11\). Its probability is the probability of that output.
When different procedures induce the same distribution, observations of individual outputs alone cannot distinguish their mechanisms. If the aim is to reproduce the source’s output statistics, either procedure can meet it.
1.3 From two pixels to general generative modeling
The two-pixel problem supplies a known distribution on four outcomes. For realistic data, both the number of possible outcomes and the uncertainty about their probabilities grow. To learn from a finite dataset, we need a representation that captures regularities shared by many outcomes.
1.3.1 Why does a table become impractical?
One binary image is a fixed vector \(x=(x_1,\ldots,x_d)\), with each \(x_i\in\{0,1\}\). A generative model assigns probabilities to the possible values of the entire image \(X\). Its table has one entry \(Q(X=x)\) for each complete image \(x\).
There are \(2^d\) possible images. Since a generation run returns exactly one of them, their probabilities satisfy
\[ \sum_{x\in\{0,1\}^d}Q(X=x)=1. \]
This sum runs over complete images. In the two-pixel case it is \(Q(00)+Q(01)+Q(10)+Q(11)=1\). Choosing three entries determines the fourth. In general, an unrestricted table has \(2^d-1\) free probability parameters, subject to nonnegativity. A \(10\times10\) binary-image model would require \(2^{100}\) table entries. This counts parameters of a distribution over images, whereas an individual image has \(d\) binary pixel values.
There are two obstacles. Storage and computation grow exponentially if we enumerate configurations. Statistical estimation also becomes difficult because a finite dataset leaves most entries unobserved. Estimating each configuration independently gives little basis for assigning probabilities to unseen configurations.
Pause 3. For \(d=20\), how many free parameters does the table have? If the training set contains \(10{,}000\) images, what is the minimum number of configurations absent from it?
There are \(2^{20}\) configurations. Each training image can account for at most one distinct configuration.
Generative learning chooses a family \(Q_\theta\) whose parameters can be estimated from the available observations. A compact family makes assumptions that let one observation inform the probabilities of many other outcomes. Maximum likelihood provides one rule for fitting those parameters. A later note will examine maximum likelihood in detail.
1.3.2 What structure can we exploit?
Here structure means statistical regularities that admit a shared description. In the two-pixel source, the rule “both pixels copy one fair bit” describes the entire joint distribution. Extending that rule to \(d\) pixels still requires only one random bit, even though the space contains \(2^d\) configurations.
Large dimensionality by itself supplies no such simplification. An arbitrary distribution on binary images can require the full table. Efficient modeling relies on the hypothesis that the source has regularities we can represent with fewer parameters, to the accuracy relevant to our task.
Natural data provide reasons to investigate this hypothesis. Spatially local interactions and recurring patterns appear in images. Grammatical constraints create dependencies across text. Shared factors can coordinate many observed components. These suggest locality, parameter sharing, and latent variables as modeling assumptions. Their adequacy must be checked against observations.
Structure check. Suppose all \(d\) pixels copy a fair bit. Compare this source with a model that chooses each pixel independently and fairly. Both give each pixel the correct black-white frequency. What probability does each assign to the event that all pixels agree?
The event consists of two configurations, all zeros and all ones. Under independence, each complete configuration has probability \(2^{-d}\).
A compact representation must preserve the relevant dependencies. The independent-pixel model has a short description, but its agreement probability reveals a mismatch with the source.
1.3.3 How can a model capture structure efficiently?
One approach uses conditional factorization. The chain rule gives \[ Q(x_1,\ldots,x_d)=Q(x_1)\prod_{i=2}^{d}Q(x_i\mid x_1,\ldots,x_{i-1}). \]
This identity supplies a sequential sampler. It becomes a compact model when the conditionals share parameters or depend on a restricted context. For example, fix \(d\geq2\) and assume a fair first bit, followed by transitions that depend only on the preceding bit. Each transition repeats that bit with probability \(r\) and flips it with probability \(1-r\). Then \[ Q_r(x_1,\ldots,x_d)=\frac12\prod_{i=2}^{d}Q_r(x_i\mid x_{i-1}). \]
One parameter specifies probabilities for every sequence. Observed transitions provide evidence about the same parameter wherever they occur. To sample, draw a fair first bit and apply the repeat-or-flip rule with fresh randomness at each step. For independent training sequences, the maximum-likelihood estimate \(\hat r\) is the fraction of adjacent pairs that agree.
Pause 4. Suppose the training sequences are \(000\) and \(011\). Compute \(\hat r\). What probability does the model assign to \(001\), which was absent from training?
Count adjacent pairs within each sequence. To evaluate \(001\), trace the first bit, a repeat, and a flip.
When \(0<\hat r<1\), every sequence has positive probability. Generation can produce unseen examples because the learned transition rule applies to every prefix. This sharing also limits the model, since the next bit depends only on its immediate predecessor. More expressive autoregressive models can condition on the full prefix while sharing neural-network parameters.
A second approach uses latent variables. The two-pixel sampler coordinates observations through a shared hidden bit. A general model can sample \(Z\) from a simple prior and generate \(X\) conditional on \(Z\). The decoder shares parameters across latent values, allowing different configurations to arise from the same learned construction. A later note will develop this representation and its training objective through variational autoencoders.
These choices create different computational problems. Conditional factorization can make likelihood evaluation straightforward while requiring sequential sampling. A latent-variable generator can be easy to sample, yet evaluating an observation’s likelihood may require a difficult sum or integral over latents. We must assess a representation by its expressiveness, the evidence needed to learn it, and the cost of likelihood evaluation and sampling.
Transfer exercise. Close the notes and fit the repeat-or-flip model using only \(000\) and \(111\). Which length-three sequences can the fitted model generate? If the source actually flips with a small positive probability, what does the fitted model miss?
Look at the fitted repeat probability when every observed adjacent pair agrees.
1.4 Worked solutions
1.4.1 Pause 1 · Compare distributions
| Program | \(00\) | \(01\) | \(10\) | \(11\) |
|---|---|---|---|---|
| A | \(1\) | \(0\) | \(0\) | \(0\) |
| B | \(1/4\) | \(1/4\) | \(1/4\) | \(1/4\) |
| C | \(1/2\) | \(0\) | \(0\) | \(1/2\) |
Under B and C, each pixel is black with probability \(1/2\). Under B, the two pixels disagree with probability \(1/2\). Under C, they always agree, so C matches the source.
1.4.2 Pause 2 · Change the sampler or its input
With fair input, both maps give \(00\) and \(11\) equally often. They assign the images to opposite input bits. With \(P(Z=1)=3/4\), \(G\) outputs \(11\) with probability \(3/4\), while \(G'\) outputs \(11\) with probability \(1/4\). The output law depends on both the input distribution and the map.
1.4.3 Pause 3 · Count the unknowns
There are \(2^{20}=1{,}048{,}576\) configurations and \(1{,}048{,}575\) free probability parameters. Even if all training images differ, at least \(1{,}048{,}576-10{,}000=1{,}038{,}576\) configurations remain unobserved. Assigning probabilities to them requires assumptions about the distribution.
1.4.4 Structure check · Compare dependencies
The shared-bit source makes all pixels agree with probability one. Under the independent fair-pixel model, the all-zero and all-one configurations each have probability \(2^{-d}\). Their total probability is \(2^{1-d}\). Matching each pixel’s individual frequency therefore leaves a large discrepancy in the joint behavior.
1.4.6 Transfer · Check a boundary fit
Every observed transition is a repeat, so \(\hat r=1\). The first bit still varies, but all later bits copy it. The only possible outputs are \(000\) and \(111\), both already observed. If the source sometimes flips, the fitted model assigns zero probability to some possible source outcomes.