Autoregressive models
Exact probability from conditionals: a synthetic sensor, bits per symbol, training and sequential sampling, PixelCNN masks and their blind spot.
One value at a time
In Latent diffusion, a sampling step updates a whole latent. Here we take another route: predict one value from the values already known. This gives an exact probability for a complete record, but ordinary sampling must build that record in order.
Imagine a sensor reporting 0 or 1 at each of 12 time steps. There are possible records. Even two values per step create many combinations. The chain rule rewrites their joint probability:
It follows by repeatedly applying . At a prefix of positive probability, the conditional is defined by the usual ratio. At a zero-probability prefix, any normalized conditional can be assigned: the joint remains zero.
This identity works for any coordinate order. It does not assert independence, a first-order Markov property or physical causation. Those restrictions enter when we choose a model for each factor. For images, a common order is left to right within each row, then top to bottom; colour channels can be ordered R, G, B inside each pixel.
Where parameter savings come from
Rewriting the probability does not automatically compress the model. For binary values, factor has possible histories. One free probability for each history still gives parameters in total.
The sensor may keep its previous state most of the time. A first-order Markov model uses only that previous state. With a separate transition rule at each position, it needs one initial probability and two per later position. Sharing the same transition rule across positions is another assumption; then only three free probabilities remain.
For a 12-step record:
| Representation | Free parameters |
|---|---|
| Unrestricted joint table | 4095 |
| Independent values | 12 |
| First-order, position-specific transitions | 23 |
| First-order, shared transitions | 3 |
A logistic conditional can retain the entire prefix while restricting how it acts:
There are weights and one bias at position , hence parameters: 78 for this sensor. This is the fully visible sigmoid belief network. A neural network can express richer interactions and share parameters across positions. The gain comes from these modelling choices, not from the chain rule alone.
Normalization and record probability
Every conditional must sum to one over the next value. That local requirement normalizes the whole joint: sum over first, remove its factor because its sum is one, then repeat for down to . No sum over every possible record is needed when evaluating one record.
For a separate three-step toy, choose:
The last factor intentionally ignores : this is a modelling restriction. A zero outcome uses the complementary probability. For example, . For a different record, select its own branch at every step.
Multiplication can underflow for long records, so work with log probabilities:
Maximum likelihood minimizes the sum of next-value cross-entropies. A Bernoulli distribution handles binary readings; a categorical softmax can handle 256 possible pixel values. Both give discrete probabilities, not continuous densities.
Bits per symbol
A log-likelihood needs units. For a record of discrete values, bits per dimension (bits per symbol for the sensor) is
Lower held-out bpd means the model assigns higher probability per value to those records. A uniform binary model costs one bit per symbol; a uniform model over 256 levels costs eight. These baselines solve different prediction problems.
Compare models on the same held-out data, representation and number of levels. Reducing the number of levels discards information and can lower bpd without improving a model for the original data. An ideal coding interpretation also assumes the model is already shared; a real file adds model, format and coding overhead. Low bpd alone does not establish perceptual quality or diversity.
Training and generation
During training, every observed value is available. Teacher forcing feeds the true prefix to each next-value prediction. If a masked convolutional network forbids access to the current and later input values, one forward pass can calculate all conditionals for the observed record. Training then sums their losses. This does not make every recurrent architecture parallel: PixelRNN still has recurrent computation within a pass.
During ordinary ancestral sampling, the prefix has to be generated. First draw ; use that result to draw ; append it and continue. Computing every output of a network on an incomplete image does not make all those outputs usable: later predictions require values that have not been drawn yet.
Caching avoids repeated work, and specialized samplers can use other strategies. The basic method still has a sequential dependency per generated value. A shared first-order sensor model makes each step cheap; a large image model can make the same dependency expensive.
Masks without leakage
For a grayscale image in raster order, a mask A keeps kernel cells above the centre and cells to its left in the same row. It removes the centre and all later cells. A example is:
1 1 1
1 0 0
0 0 0Here 1 allows a connection, not a fixed weight. Apply A to the raw input first: otherwise the prediction can read the value it is supposed to predict.
Later hidden layers use mask B, which also keeps the centre. This is safe because the hidden feature at the centre already depends only on earlier input values. It is not permission to reconnect the raw target pixel. A path from any forbidden input to an output would violate the factorization.
For RGB images, channel masks must also respect the within-pixel order: green can depend on red, blue on red and green. An unmasked channel-mixing operation can leak the current or a later channel even if the spatial mask looks correct.
Missing parts of the past
Causal does not mean complete. Stack four masked convolutions, A first and B afterwards, without dilation. At an interior position, an earlier input four rows above can reach four columns to the right. An input one row above can reach only one column to the right. Moving right requires moving up in a kernel; horizontal movement within the same row only goes left.
Within the four rows above and four columns to either side, some earlier pixels therefore have no path to the output. This missing upper-right region is the blind spot. It is an architectural limitation, not an independence assertion about real images. More layers enlarge the reachable region but do not turn the finite stack into unrestricted access to the whole past.
Gated PixelCNN separates vertical features from earlier rows and horizontal features from earlier positions in the current row. Information can flow from the vertical stack into the horizontal stack. Passing unrestricted horizontal features back into the vertical stream can leak values to the right when the streams are combined. The dependency paths, not just the shape of a drawing, determine whether the model is valid.
What the experiment checked
We now have two different questions. Is the model normalized? Normalized, past-only conditionals make the chain product a valid joint. Is it a good model? That requires enough useful context, suitable parameters, data and evaluation. A small normalized model can still miss the patterns we care about.
The optional notebook fits the shared-transition model to 2048 newly generated 12-step sensor records and evaluates 256 separate records. The generator switches state with probability 0.17; the fitted model estimates its two transition probabilities separately. Add-one counts keep both outcomes possible. The saved run obtains about 0.6683 bits per symbol, against 1 for the uniform binary baseline, and enumerating all 4096 records gives total probability 1. Prefix completions preserve the supplied first three values.
These are local results on synthetic data, not a PixelCNN implementation or an image-generation benchmark. No external dataset, model or download is needed. The notebook is optional; the lesson's questions stand on their own.
For images, a long chain and a limited convolutional context remain costly. Autoregressive transformers use causal attention over discrete image tokens: a learned representation can shorten the chain, while attention changes how a token uses its prefix.
This lesson follows the reviewed FP note. Architectural sources: PixelRNN / PixelCNN and Gated PixelCNN. The linked note retains the further scientific references. The synthetic examples and notebook were authored for this project with Codex assistance.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Go deeper — optional
Code and labs do not count toward the main percentage or the certificate.
- Sensor: probability and prefix completionoptional
Fit a Markov model to synthetic records. Check normalization, bits per symbol and completion of a given prefix. No downloads or third-party libraries.
~20 min · easier on a computer · The autoregressive-model lesson; Python lists and functions.
Self-check in the notebook — not part of mastery or the certificate.
Answers are saved on the server and tied to this browser until you sign in.