Skip to content
中文

A small language for generative models

An interactive field guide

A generator must choose among many possible images. Before studying its network, separate a value, a distribution, and a conditional distribution.

A tensor is an array with a shape. B is the number of examples, C the number of channels, and H and W the image height and width. An image batch often has shape [B,C,H,W]. A sequence often has shape [B,N,D]: N positions, D numbers at each position. A token can be an integer ID or a vector.

A latent z is an internal representation. An encoder maps an observed image x into z. A decoder maps z back to an image or to a distribution over images. A prior describes which z values the model expects before it sees x. Reconstruction starts from an observed image; generation may start from a prior sample.

Read from left to right. Select a module to connect its role, tensor shape, and calculation. Snippets are teaching pseudocode. Sources provide the paper method or audited implementation.

Observe

The input is a value, not a density.

x = batch["image"]

Represent

A learned map changes the representation.

z = encoder(x)

Model

The head assigns probabilities or defines a density sampler.

next_z = sample(head(context))

Inspect the pinned source

p(z1,…,zN)=∏i=1Np(zi∣z<i)p(z_1,\ldots,z_N)=\prod_{i=1}^{N}p(z_i\mid z_{<i})

Use the controls to change two binary probabilities. If P(first=1)=0.6 and P(second=1|first=1)=0.7, the joint event has probability 0.42. The remaining event with first=1 has probability 0.18. These add to 0.6. The conditional distribution must still sum to one.

The chain rule does not assume that positions are independent. It only chooses an order for writing the joint distribution. A causal model learns these conditional distributions with a mask. Continuous variables use densities rather than probabilities of exact values; their densities need not be less than one.

Change a parameter, inspect the computed values, then compare this small example with the model described above.

Analytical teaching model · controls change the example, not a trained research model.

P(first = 1)P(first = 1, second = 1)

The second probability is conditional. Multiplying marginal probabilities would assume independence.

Computed values for the current example
QuantityValue
P(1,1) = P(1) P(1|1)0.420
P(1,0) = P(1) [1 − P(1|1)]0.180

A loss is a training objective, not automatically a measure of image quality. Negative log-likelihood rewards probability assigned to observed data. Squared error corresponds to a Gaussian likelihood only with stated variance assumptions. Averaging over pixels versus summing changes its scale.

A smaller tensor is not necessarily a better representation. Count positions, channels, precision, and the cost of the model that consumes them. Do not compare 256 integer codes with 256 vectors as if both carry the same information.

Is a continuous token already a probability distribution?

No. It is a value. A model must separately define how possible values are distributed.

Return to the learning map

Diagrams and snippets are teaching reconstructions. Paper reports, implementation observations, and analytical examples are distinguished. No research model runs in this page.