Autoregressive Generation: PixelCNN and WaveNet
PixelCNN and WaveNet generate images and audio one element at a time, each new value predicted from every value already generated before it, using masked or causal convolutions to guarantee the model never cheats by looking ahead.
Prerequisites: Vector-Quantized VAE (VQ-VAE)
The most direct way to define a generative model is to write down as a product of one-step-at-a-time conditional probabilities and predict each in turn: . No latent variable, no adversarial game — just predict the next element given everything before it, exactly, using the chain rule of probability, which holds for any distribution with no approximation at all. PixelCNN applies this to images, pixel by pixel; WaveNet applies it to raw audio, sample by sample. Both live or die on one architectural guarantee: the model predicting position must never be allowed to see positions
The analogy: filling in a crossword, one square at a time, blind to the answer key
Autoregressive generation is like solving a crossword by filling in one square at a time, using only the squares already filled and the clues — never peeking at squares not yet reached, and never at the answer key. Each square's fill is a genuine prediction conditioned only on what's legitimately known so far. If you accidentally let yourself glance at a not-yet-filled square while solving the current one, you're not really solving the puzzle sequentially anymore — you're cheating, and the "prediction" you write down is not one the model could actually make at generation time, when future squares genuinely don't exist yet.
The masking trick that enforces this
A standard convolution centered on pixel sees neighbors on every side, including "future" ones in raster-scan order. PixelCNN's masked convolutions zero out the filter weights that would look at not-yet-generated pixels, so the receptive field only ever includes pixels above and to the left (in scan order). WaveNet does the equivalent in 1-D with causal convolutions, restricting each output at time to inputs at times , then stacking dilated versions of these (as in QuantGAN) to reach far back in the sequence cheaply:
In words: the whole sequence's probability is the product of each element's probability given only the elements strictly before it — no term in this product is allowed to depend on anything to its right.
Worked example 1: computing a sequence probability from per-step predictions
Suppose a trained autoregressive model outputs these categorical probabilities for a 3-symbol binary sequence: , then given , , then given , . The probability of the specific sequence is the product: . Every autoregressive log-likelihood computation is exactly this — a sum of log-probabilities, one per position, each conditioned only on genuinely-prior positions — which is also directly why training is easy: teacher-forcing feeds the real previous values at every position in parallel and computes all these conditional log-probabilities in one forward pass.
Worked example 2: why generation is still sequential even though training isn't
Training can compute all conditional probabilities in one parallel forward pass, because the real are already known for every simultaneously. Generation cannot: to sample you need the actual sampled (not the real training data, which doesn't exist yet), so generating a length-1,000 sequence requires 1,000 sequential forward passes, one per new sample, each depending on the output of the last. If one forward pass costs 2 milliseconds, generating one 1,000-length sample costs roughly seconds — versus training, where a full batch of many such sequences costs about the same 2 milliseconds per sequence position, computed all at once. This training/generation asymmetry is the central practical cost of every purely autoregressive generator.
A Brownian path is itself autoregressive in the loosest sense — each step depends only on where the path currently is; PixelCNN and WaveNet are the same idea with the "next step" rule learned by a deep network instead of fixed by a formula.
Autoregressive models like PixelCNN and WaveNet factor the exact joint probability of a sequence into a product of one-step-ahead conditionals, enforced with masked or causal convolutions so no position can see the ones after it — an exact factorization, not an approximation, but one that forces sequential, not parallel, generation.
What this means in practice
Autoregressive generation is the natural choice whenever exact likelihoods matter (for model comparison, anomaly scoring, or compression) and when data is naturally ordered — which includes essentially all financial time series. It's also the standard second stage after a VQ-VAE compresses data to discrete tokens, since a discrete token sequence is exactly the input shape autoregressive models were built for.
It's tempting to assume an autoregressive model trained with teacher forcing (always conditioning on real past values) will behave the same at generation time, when it must condition on its own past predictions instead. Small errors early in a generated sequence can compound, since the model has never been trained on the specific kind of "slightly wrong" input its own mistakes produce — a phenomenon called exposure bias, and a reason autoregressive samples can degrade in quality the longer the sequence runs.
Related concepts
Practice in interviews
Further reading
- van den Oord et al., Pixel Recurrent Neural Networks (2016)
- van den Oord et al., WaveNet: A Generative Model for Raw Audio (2016)