# Hierarchical Text-Conditional Image Generation with CLIP Latents

unCLIP generates images by first predicting CLIP image embeddings

Aditya Ramesh, Prafulla Dhariwal, Alex Nichol, Casey Chu, Mark Chen · arXiv · 2022-4-13

- **Problem** Guidance makes text-to-image samples more photorealistic but less diverse, so models trade one for the other. Generating a single image directly from a caption gives no easy way around this trade-off.
- **Method** unCLIP first uses a prior to turn a caption into a CLIP image embedding. A diffusion decoder then renders an image from that embedding, so one embedding can yield several different images.
- **Results** unCLIP with the diffusion prior scored a zero-shot FID of 10.39 on MS-COCO, compared to 12.24 for GLIDE.

## Why guidance trades diversity for fidelity

Their best samples depend on guidance, which raises fidelity, meaning photorealism for images, at the cost of diversity. For a text-to-image generator, that trade-off means sharper images can come with a narrower range of outputs for the same caption.

CLIP offers a different starting point, because its image embeddings are robust to distribution shift and work zero-shot. The question is whether generating the CLIP image representation first can raise diversity while photorealism and caption similarity hold up.

## Generating a CLIP embedding before the image

unCLIP splits generation into two stages: a prior maps a caption to a CLIP image embedding, and a diffusion decoder renders an image from that embedding. The embedding carries the semantic content, and the decoder fills in the details the embedding leaves out. Because the decoder is non-deterministic, one embedding can yield several different images, which is how the design targets diversity.

The authors explain the diversity gain by saying that the scene's semantics are fixed in the CLIP embedding, so decoder guidance can't collapse them. Formally, the image distribution is factored through the embedding, as follows. \\\[ P(x \\mid y) = P(x, z\_i \\mid y) = P(x \\mid z\_i, y)\\,P(z\_i \\mid y) \\\] The first step holds because the image fixes its embedding, and the second is the chain rule.

Sampling the embedding from the prior and then the image from the decoder therefore draws from the true conditional distribution.

## How the diffusion decoder uses the embedding

The decoder starts from the GLIDE architecture and feeds the CLIP image embedding in two ways. The embedding is added to the timestep embedding, and it is also projected into four extra context tokens appended to the GLIDE text encoder outputs. The GLIDE text pathway is kept in case it can learn language aspects CLIP misses, such as variable binding, though the authors find it helps little here.

During training the CLIP embedding is set to zero 10% of the time, and the caption is dropped 50% of the time, which enables classifier-free guidance at sampling. High resolution comes from two upsamplers, one taking 64×64 images to 256×256 and another taking those to 1024×1024. The upsamplers train on corrupted conditioning images, with Gaussian blur for the first stage and a BSR degradation for the second, so they tolerate imperfect inputs.

The upsamplers train on random crops one-fourth the target size and use only spatial convolutions. The authors found no benefit from conditioning the upsamplers on the caption, so they stay unconditional.

## Two priors for the image embedding

The autoregressive prior needs a short discrete sequence, so the authors first compress the CLIP image embedding with PCA. Keeping 319 of the 1,024 principal components preserves nearly all the information, with under 1% average mean-squared reconstruction error. Each retained dimension is quantized into 1,024 buckets, and a causal Transformer predicts the resulting sequence conditioned on the caption.

Predicting this sequence cuts the number of tokens predicted at inference threefold.

The caption and the CLIP text embedding are prefixed to the sequence, and a token holding the quantized dot product of text and image embeddings tells the model how well the caption fits. At sampling time the dot product is drawn from the top half of its distribution, since higher values match captions that describe the image better. The authors swept percentiles of 50%, 70%, 85% and 95% and found 50% best in all experiments.

The diffusion prior works on the continuous embedding directly, with a decoder-only Transformer under a causal mask. Its input sequence holds the encoded text, the CLIP text embedding, a timestep embedding, the noised image embedding and a final output token. Rather than predicting the noise, the model predicts the unnoised embedding, trained with a mean-squared error loss.

\\\[ L\_{\\text{prior}} = \\mathbb{E}\_{t \\sim \[1,T\],\\; z\_i^{(t)} \\sim q\_t}\\left\[\\left\\\| f\_\\theta(z\_i^{(t)}, t, y) - z\_i \\right\\\|^2\\right\] \\\] At sampling time it draws two candidate embeddings and keeps the one with the higher dot product with the text embedding, in place of conditioning on that dot product.

## Is the prior needed at all?

Conditioning the decoder on the caption alone is possible, but it underperforms a model trained that way, which the authors identify with GLIDE. Feeding the CLIP text embedding to the decoder as if it were an image embedding also works zero-shot, as earlier work observed.

The authors trained two small models and compared a decoder on CLIP text embeddings, a small unCLIP stack, and text embeddings fed zero-shot to the unCLIP decoder. On a test set these scored FIDs of 9.16, 7.99 and 16.55, so the full unCLIP stack came out ahead. Humans preferred the full stack 57.0%± 3.1% of the time for photorealism and 53.1%± 3.1% for caption similarity.

These are small models with swept sampling settings, so they serve as an early check before the full human study.

## Human judgments against GLIDE

The authors ran pairwise human comparisons on photorealism, caption similarity and diversity, each with a third option for not being sure. The first two follow earlier protocols, while diversity uses two 4×4 grids of samples for the same caption, drawn from 1,000 MS-COCO validation captions. Before the human runs, a CLIP linear probe trained as a proxy for photorealism judgments was used to sweep hyperparameters, which were then fixed.

With the diffusion prior, photorealism reached 48.9% ± 3.1% and caption similarity 45.3% ± 3.0%, compared to 47.1% ± 3.1% and 41.1% ± 3.0% with the AR prior.

Diversity is the clearer result: unCLIP with the diffusion prior was preferred 70.5% ± 2.8% of the time, compared to 62.6% ± 3.0% with the AR prior. The authors read this as a benefit of generating the embedding first, and they note the diffusion prior does better than the AR prior in these comparisons in general.

## Guidance and the diversity trade-off

When guidance scale rises for both models, GLIDE's camera angle, color and size converge. unCLIP keeps its scene semantics, because the embedding is fixed and only the decoder's guidance changes.

The authors also sweep decoder guidance and measure MS-COCO zero-shot FID, holding the prior's guidance fixed. Guidance raises unCLIP's FID much less than GLIDE's. FID penalizes non-diverse generations, so the authors read the smaller rise as evidence that guidance costs unCLIP less diversity.

In the human study, GLIDE at guidance scale 2.0 came very close to unCLIP on photorealism and caption similarity. Its samples were still less diverse, so matching unCLIP on fidelity costs GLIDE its variety.

## Zero-shot FID on MS-COCO

At 256×256 with decoder guidance scale 1.25, unCLIP with the diffusion prior scored a zero-shot FID of 10.39, compared to 12.24 for GLIDE. The AR prior scored 10.63, so the diffusion prior leads by a small margin on this metric. Among the zero-shot methods in the comparison, the authors report a new state of the art at 10.39.

unCLIP was not trained on the MS-COCO training set, yet it generalizes to the validation set zero-shot, as GLIDE and DALL-E do. The table also gives a filtered FID column, where the diffusion prior scored 10.87. This rests on one benchmark and one metric, so the margin over the AR prior is small.

## Aesthetic quality and recall

The authors generated 512 artistic captions with GPT-3 and produced four images per prompt, averaging over a batch of 2048 images. A CLIP linear probe trained on the AVA dataset scores each image for predicted aesthetic judgment. For unCLIP only the decoder is guided, since the authors found that guiding the prior hurt results.

Guidance improves aesthetic quality for both GLIDE and unCLIP. Recall is computed against the training dataset, and guiding unCLIP does not decrease it while aesthetic quality rises. These aesthetic scores come from an automated probe rather than human raters, so they show what the probe prefers.

## What the bipartite latent allows

An input image is encoded as a pair: its CLIP image embedding z\_i, and a DDIM latent x\_T obtained by DDIM inversion with the decoder conditioned on z\_i. The embedding describes what CLIP recognizes, while the latent holds the residual detail the decoder needs to rebuild the image. With η equal to 0 the decoder reconstructs the image, and with η greater than 0 it produces variations that stay centered on the original.

Interpolation rotates between two CLIP embeddings by spherical interpolation while the DDIM latent is fixed to a random sample. Text diffs move the image embedding toward the normalized difference of two CLIP text embeddings, with θ rising linearly from 0 to a maximum typically in \[0.25, 0.50\]. The base DDIM noise stays fixed along the trajectory, so the layout is kept while the edit applies.

Examples include turning a photo of a cat into an anime drawing and turning a winter landscape into a fall one.

The authors test typographic attacks, where overlaid text makes CLIP name the written object, to see what the decoder shows. In the paper's example an apple is misclassified as an iPod. The decoder still produced apples even when the predicted probability for Granny Smith was near zero, and it never produced iPods despite a high probability for that label.

Reconstructions from increasing PCA dimensions, from 20 up to 320, show that early dimensions carry coarse semantics. Later dimensions encode finer shapes and the exact form of objects. The AR prior is trained to predict these components in this order, so the same reconstructions also show what it models.

## Limitations

unCLIP binds attributes to objects less well than GLIDE, and it struggles more in a prompt with two cubes of different colors. Decoder reconstructions often swap attributes between objects, and the authors hypothesize that the CLIP embedding doesn't explicitly bind attributes to objects.

unCLIP also struggles to render coherent text. The authors suggest the CLIP embedding may not precisely encode spelling, and the BPE encoding hides spelling from the model.

Complex scenes lack detail, which the authors attribute to generating a 64×64 base image before upsampling. The authors expect a higher base resolution to help, at extra training and inference cost, but the paper doesn't test this. The authors also note that unCLIP's performance gains raise its risk profile over GLIDE, since generated images are harder to tell from authentic ones.

## Paper info

- **Authors**: Aditya Ramesh, Prafulla Dhariwal, Alex Nichol, Casey Chu, Mark Chen
- **Venue**: arXiv · Preprint
- **First published**: 2022-4-13
- **Added**: 2026-11-11
- **Updated**: 2022-4-13
- **Version**: v1
- **arXiv**: 2204.06125
- **Category**: cs.CV
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2204.06125v1) · [PDF ↗](https://arxiv.org/pdf/2204.06125v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Aditya Ramesh, Prafulla Dhariwal, Alex Nichol, Casey Chu, Mark Chen (2022). Hierarchical Text-Conditional Image Generation with CLIP Latents. arXiv:2204.06125v1. https://arxiv.org/abs/2204.06125v1

**BibTeX**

```
@misc{ramesh2022hierarchical,
  title = {{Hierarchical Text-Conditional Image Generation with CLIP Latents}},
  author = {Aditya Ramesh and Prafulla Dhariwal and Alex Nichol and Casey Chu and Mark Chen},
  year = {2022},
  eprint = {2204.06125},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2204.06125v1}
}
```

## Other paper commentary

- [GANs Trained by a Two Time-Scale Update Rule Converge to a Local Nash Equilibrium](https://refivu.com/en/papers/e19fb2a4-2e7f-47ba-9ba7-ba5660b1efb6-gans-trained-by-a-two-time-scale-update.md)
- [Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network](https://refivu.com/en/papers/5a2dbd66-c794-464b-9d10-02f19eeb20e7-photo-realistic-single-image-super-resolution-using-a.md)
- [Explaining and Harnessing Adversarial Examples](https://refivu.com/en/papers/37bc09da-a299-4ed8-8384-7f87f7409fd4-explaining-and-harnessing-adversarial-examples.md)
- [Large Scale GAN Training for High Fidelity Natural Image Synthesis](https://refivu.com/en/papers/93f6ad29-8cca-4630-9a3b-d12f9ad91854-large-scale-gan-training-for-high-fidelity-natural.md)
- [DU-GAN: Generative Adversarial Networks with Dual-Domain U-Net Based Discriminators for Low-Dose CT Denoising](https://refivu.com/en/papers/46030b78-75d0-4156-80ef-e92602d09b95-du-gan-generative-adversarial-networks-with-dual-domain.md)
- [Generative Modeling by Estimating Gradients of the Data Distribution](https://refivu.com/en/papers/f3ef856d-6161-4eaa-b2c9-6a0c3f1ff432-generative-modeling-by-estimating-gradients-of-the-data.md)
- [On the Properties of Neural Machine Translation: Encoder-Decoder Approaches](https://refivu.com/en/papers/63546f31-7951-40c2-8cd8-fccae107022a-on-the-properties-of-neural-machine-translation-encoder.md)
- [Overcoming catastrophic forgetting in neural networks](https://refivu.com/en/papers/e39e1a97-7b59-4a3d-95cd-a82be4c40f43-overcoming-catastrophic-forgetting-in-neural-networks.md)
- [GPT-4o System Card](https://refivu.com/en/papers/7f73de51-bae5-43e2-85f2-6decfe19e7c4-gpt-4o-system-card.md)
- [An overview of gradient descent optimization algorithms](https://refivu.com/en/papers/96d69873-e1ce-41dd-9333-645272090396-an-overview-of-gradient-descent-optimization-algorithms.md)
- [Wide Residual Networks](https://refivu.com/en/papers/1bd6014c-67f5-4e80-9e66-e667155a3f6e-wide-residual-networks.md)
- [Beyond a Gaussian Denoiser: Residual Learning of Deep CNN for Image Denoising](https://refivu.com/en/papers/42b88b1a-7986-4ec5-b7e5-406b2cec7f9e-beyond-a-gaussian-denoiser-residual-learning-of-deep.md)

## Terms in this paper

- [Transformer](https://refivu.com/en/terms/48e8be2570bc-transformer)
- [FID](https://refivu.com/en/terms/e110afe65f86-fid)
- [recall](https://refivu.com/en/terms/3774987267f3-recall)
- [CLIP](https://refivu.com/en/terms/b5b5b48d5f4e-clip)
- [diffusion models](https://refivu.com/en/terms/39b044617fcd-diffusion-models)
- [MS-COCO](https://refivu.com/en/terms/3c7d75a4a2eb-ms-coco)
- [DDIM](https://refivu.com/en/terms/6c24451d09a5-ddim)
- [Principal Component Analysis (PCA)](https://refivu.com/en/terms/84a4d2030ed5-principal-component-analysis-pca)
- [Diversity](https://refivu.com/en/terms/4da09e0589f4-diversity)
- [GLIDE](https://refivu.com/en/terms/7e2bcf7f5925-glide)
- [Guidance](https://refivu.com/en/terms/8f6c40d43c17-guidance)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/a54e72c7-9aba-4f0a-b093-9f8704564243-hierarchical-text-conditional-image-generation-with-clip)
