Text to image: DALL·E's tokens and unCLIP's prior
Two routes from a prompt to a picture: write the image as discrete tokens after the text (DALL·E), or turn the caption's CLIP embedding into an image embedding and decode it with diffusion (unCLIP).
What runs in CodeSplash
- MM019DALL·E: original autoregressive text-to-image model Runs as a notebook
- MM020DALL·E 2 / unCLIP Explained here
You will be able to
- Explain how a discrete image tokenizer lets a Transformer generate images
- Compute the negative log-likelihood of image tokens given a text prefix
- Describe unCLIP's prior and decoder and what each one generates
- Judge generated images on fidelity, diversity, prompt adherence and failure rate
Images as a second language
ReadA Transformer generates text one token at a time. To generate images the same way, an image must become tokens. A discrete image tokenizerDiscrete image tokensAn image encoded as a grid of codebook indices, so a Transformer can generate it token by token like text., such as a discrete VAE or VQ-VAEVQ-VAEAn autoencoder whose code snaps to the nearest of a fixed set of learned vectors, giving discrete codes instead of Gaussian ones., compresses an image into a small grid of codebook indices and can decode such a grid back to pixels.
The original DALL·E used a 32 × 32 grid with 8,192 possible codes for a 256 × 256 image. A caption followed by its image is then one long sequence of tokens.
DALL·E: text, then image tokens
ReadDALL·E trained a large Transformer to predict the next token of caption-plus-image sequences. To generate, it reads the prompt, samples image tokens one at a time, decodes the grid to pixels, and makes many candidates that CLIP then reranks by how well they match the prompt.
Training minimizes the negative log-likelihood of each image token given the text and the tokens before it. In the program, three image tokens follow the prefix "a red cube"; their summed negative log-likelihood is 1.091.
Sampling tokens like words
ExploreEach image token is drawn from a probability distribution, exactly as a word is. Temperature and top-p trade variety against safety in the same way, and one unlucky early token shapes everything after it:
DExplorable · Temperature and top-p
What do the sampling settings on a language model actually change?
With these settings, how likely is the single most likely token?
Below 1 sharpens the distribution; above 1 flattens it.
Keep the likeliest tokens until they hold this much probability.
“The p-value tells you how extreme”
- With these settings
- Default (temperature 1, no cut-off)
Twelve sampled tokens: extreme · surprising · surprising · unusual · rare · rare · unusual · surprising · rare · extreme · surprising · likely
Commit your prediction above to see the result
Make your prediction to see the result.
How long is the sequence?
PredictPredict first
A tokenizer turns a 256 × 256 image into a 32 × 32 grid of codes. How many image tokens must the Transformer generate, one at a time?
Reveal
1,024. Every one of them is a full forward pass, which is why autoregressive image generation is slow, and why the tokenizer compresses so hard: generating 65,536 pixels directly would be far worse.
unCLIP: a prior and a decoder
ReadDALL·E 2, or unCLIP, works in CLIP's embedding space. A priorunCLIP priorA model that turns a caption's CLIP text embedding into a plausible CLIP image embedding, which a decoder then draws. turns the caption's CLIP text embedding into a plausible CLIP image embedding; a diffusion decoder then draws an image that has that embedding, and upsamplers enlarge it.
In the program the text embedding plus prior noise, normalized, gives the image embedding (0.994, 0.110), which a toy linear decoder expands into three features. Splitting the work allows image variations: keep one image embedding, sample the decoder again.
How a diffusion decoder turns noise into samples, and what guidance does.
DExplorable · Diffusion: noise schedule, sampler steps, guidance
How does a diffusion model turn noise back into data, and what do the schedule, the steps and guidance change?
With this sampler and number of steps, will the samples match the data?
β schedule
The forward process at this step: how much signal is left.
Sampler
DDPM adds fresh noise every step; DDIM is deterministic.
0 = unconditional, 1 = plain conditional, above 1 = guided.
Class to guide toward
- Noised samples
- Exact q(xₜ)
- Samples
- Data
Commit your prediction above to see the result
Make your prediction to see the result.
Judging generated images
ReadThere is no reference image, so judge four things separately: fidelity (do they look real?), diversity (do prompts give varied outputs?), prompt adherence (counts, colors, relations, text), and failure rate (how often is an output unusable or harmful?). FIDFréchet inception distance (FID)Distance between Gaussians fit to real and generated images' features; lower is closer, and it depends on the feature network. covers fidelity and diversity across many images; CLIPScoreCLIPScore2.5 × max(cosine of an image and its caption, 0): how well a caption fits its image, without reference captions. covers rough adherence, with CLIP's blind spots for counting and negation. Neither replaces a human look at a sample.
DExplorable · Scoring generators: FID, precision and recall
Can one number say how good generated samples are?
How will this generator's precision and recall come out?
Generator
The real data is a ring of 8 clusters. Each generator gets something different wrong.
Feature extractor
FID and the k-NN scores compare features, not raw samples. Real FID uses a vision network; here, four simple maps.
How many real and how many generated samples are compared.
Each sample's ball reaches its k-th nearest neighbor in its own set.
Commit your prediction above to see the result
Make your prediction to see the result.
Check: text to image
CheckpointCheck yourself
Why does DALL·E need a discrete image tokenizer?
Show the answer
Answer: a
Next-token prediction needs tokens. The tokenizer also shortens the sequence enormously compared with raw pixels.
Check yourself
After a text prefix, a model gives two image tokens probabilities 1 and 0.5. What is their summed negative log-likelihood?
Show the answer
Answer: 0.6931
−log 1 − log 0.5 = 0 + 0.693 = 0.693. Each token's surprise adds up over the sequence.
Check yourself
DALL·E generated many candidates per prompt. How were the shown images chosen?
Show the answer
Answer: a
Reranking with a separate image–text model raised apparent quality, and also hides how often single samples fail.
Check yourself
In unCLIP, what does the prior generate?
Show the answer
Answer: a
The prior works in embedding space; the diffusion decoder turns the image embedding into pixels.
Check yourself
How does unCLIP make several variations of one image?
Show the answer
Answer: a
The embedding fixes the meaning and style; decoder noise varies the details.
Check yourself
A new generator improves FID and CLIPScore. Which question do those two numbers still leave open?
Show the answer
Answer: b
FID compares distributions; CLIPScore inherits CLIP's blind spots. Targeted prompts and human review check the rest.
Recap
Recap- A discrete tokenizer turns images into codebook grids; DALL·E predicts them after the text, one token at a time.
- Training minimizes the image tokens' negative log-likelihood; sampling settings shape the output as for words.
- unCLIP's prior makes a CLIP image embedding from the caption; a diffusion decoder draws it.
- Judge generators on fidelity, diversity, prompt adherence and failure rate, with humans in the loop.
Concepts in this lesson