Text-to-image: DALL-E, Stable Diffusion, Midjourney
Condition a diffusion model on a CLIP text embedding; contrast DALL-E 2 (CLIP prior + decoder), Stable Diffusion (latent diffusion + cross-attention), and classifier-free guidance.
Text-to-image generation is the task of synthesizing a photorealistic (or stylized) image from a natural language description[1]. The three dominant approaches -- DALL-E 2, Stable Diffusion, and Midjourney -- share a foundation in diffusion models and CLIP-based text conditioning, but differ in architecture and training.
Text conditioning: the core mechanism
A diffusion model learns to denoise images. Without conditioning, it samples from the image marginal distribution . To condition on text , we sample from : images that match the text description.
The text string is encoded by a CLIP text encoder or a language model into a fixed- dimensional embedding . This embedding is injected into the diffusion model's denoising network at each step.
Injection via cross-attention: the denoising network (typically a U-Net or DiT) uses cross-attention layers where the image features (queries) attend to the text embedding (keys and values):
This mechanism is the same as in the Transformer encoder-decoder (E3), but now the "source sequence" is the text embedding and the "target" is the noisy image.
Classifier-free guidance (CFG)
Training the diffusion model conditional on text requires paired (text, image) data. But we also want to amplify the conditioning effect at inference time.
Classifier-free guidance (Ho and Salimans, 2022) trains a single model on both conditional () and unconditional (, text dropped out randomly at training) inputs. At inference, combine both predictions:
where is the guidance scale. The second term amplifies the difference between conditional and unconditional predictions, steering the sample toward high-fidelity text alignment at the cost of diversity.
- : standard conditional generation.
- : strong text alignment but lower diversity (typical for DALL-E 2, SD).
- : overfit to the text; outputs lose realism.
DALL-E 2 (OpenAI, 2022)
Two-stage pipeline:
-
CLIP prior: given the text embedding , train a diffusion model to generate the corresponding CLIP image embedding : .
-
Unclip decoder: given , generate the image pixels with a second diffusion model: .
The CLIP image embedding captures semantic content but not photographic details, so the decoder has freedom in style, lighting, and composition.
Variations: fixing and sampling different values produces semantically similar images with different visual styles.
Stable Diffusion: latent diffusion
Stable Diffusion (Rombach et al., 2022) reduces compute by running the diffusion process in a compressed latent space rather than pixel space[2].
-
VAE encoder: compress the image to a latent (8x spatial compression, 4 latent channels).
-
Diffusion in latent space: train the denoising U-Net on with text conditioning via cross-attention:
-
VAE decoder: decode the final latent back to pixel space.
Efficiency: operating on latents (for a 512px image) vs. pixels reduces memory and compute by 64x, enabling training on consumer GPUs and inference in seconds.
Text encoder: Stable Diffusion 1.x uses CLIP ViT-L text encoder; SD 2.x uses OpenCLIP; SD 3 uses three text encoders (CLIP-L, OpenCLIP-G, and T5-XXL) whose embeddings are concatenated. Conditioning on a large frozen language model (T5) for stronger text alignment was introduced by Imagen[3].
SDXL and SD 3: scaling up
SDXL (2023): larger U-Net (2.6B parameters) with an additional refiner diffusion model for high-frequency details. Second-stage refinement conditions on the base model's output.
SD 3 and SD 3.5 (2024): replace the U-Net with a Diffusion Transformer (DiT):
- Patch the latent into tokens.
- Apply transformer blocks with multi-modal attention (image patches and text tokens in the same attention operation).
- Separate streams for image and text that merge via attention.
DiT-based models scale better with parameters and produce more coherent text in images.
Midjourney
Midjourney's architecture is proprietary. Known characteristics:
- Strong artistic style; optimized for aesthetic quality over photorealism.
- Rumored to use a proprietary diffusion model trained on curated aesthetic data.
- RLHF-style feedback (users can upscale/vary; winning variants are used in training).
- V6 shows significantly improved text rendering and prompt adherence.
Evaluation
| Metric | Measures |
|---|---|
| FID (Frechet Inception Distance) | Distribution match between real and generated images |
| CLIP score | Text-image alignment |
| Human preference (ELO) | Aesthetic quality and instruction following |
| DrawBench | Compositional generation (count, color, position) |
All three systems score high on CLIP and FID but differ substantially on human preference and compositional accuracy. Text rendering (letters in images) remains an active challenge, partially addressed by SD 3 and DALL-E 3.
Exercises
Exercise 1. At a denoising step the unconditional noise prediction is and the conditional prediction is (for one coordinate). Compute the classifier-free guided prediction for guidance scales , , and . Interpret what each value means for the generated sample.
Solution
Step 1. The CFG formula is . The bracket is the conditioning direction, here .
Step 2. Substitute each scale:
Step 3. At the guided prediction equals the plain conditional one, standard text-conditioned generation. At it collapses to the unconditional prediction, the text is ignored. At the prediction is pushed far past the conditional value, amplifying text alignment at the cost of diversity and, if pushed further, realism. CFG is an extrapolation along the conditioning direction, not an interpolation.
Exercise 2. Stable Diffusion runs diffusion on instead of pixels . For a image, compute the spatial grid the U-Net operates on, the factor by which the number of spatial positions shrinks, and the ratio of total tensor elements (latent vs pixel). Explain why the lesson quotes a "64x" reduction rather than the element ratio.
Solution
Step 1. The latent grid is spatial positions, versus pixels.
Step 2. Spatial positions shrink by . The self-attention and convolution cost scales with the number of spatial positions, so this is the figure that governs compute.
Step 3. Counting channels too, total elements go from to , a ratio of . The element ratio is smaller because the latent adds a channel (3 to 4). The lesson quotes because compute and memory in the spatial attention scale with spatial positions, not channel count.
Exercise 3. DALL-E 2 uses a two-stage pipeline (a CLIP prior mapping text embedding to a CLIP image embedding, then an unCLIP decoder to pixels), while Stable Diffusion conditions a single latent-diffusion U-Net directly on the text embedding via cross-attention. Give one capability the DALL-E 2 design buys from the intermediate CLIP image embedding, and one practical advantage Stable Diffusion's design has.
Solution
Step 1. DALL-E 2's intermediate is a full CLIP image embedding. Holding the text fixed and resampling the prior produces different image embeddings, hence semantically equivalent but visually varied outputs (different style, lighting, composition). The embedding also supports image variations and embedding arithmetic, capabilities that come directly from operating in CLIP's image space.
Step 2. Stable Diffusion's single-stage latent design is simpler and cheaper: there is no separate prior model to train or run, and diffusion happens in an 8x-compressed latent, so training fits on consumer GPUs and inference takes seconds. One model, conditioned by cross-attention, end to end.
Step 3. The trade-off is modularity and embedding-level control (DALL-E 2) versus simplicity and efficiency (Stable Diffusion); both reach high CLIP and FID scores, so the choice is driven by these system properties rather than raw quality.
The same latent-diffusion and DiT machinery, with cross-attention text conditioning, extends in the next lesson from a single image to temporally coherent video.
References
- [1]Ramesh, A., et al. (2021). "Zero-shot text-to-image generation (DALL-E)". ICML. arXiv:2102.12092↩
- [2]Rombach, R., et al. (2022). "High-resolution image synthesis with latent diffusion models (Stable Diffusion)". CVPR. arXiv:2112.10752↩
- [3]Saharia, C., et al. (2022). "Photorealistic text-to-image diffusion models with deep language understanding (Imagen)". NeurIPS. arXiv:2205.11487↩