Plain-English explanation

Before a diffusion model can act on a prompt, the prompt's words need to become something the model can compute with: a set of numbers produced by a text encoder, not raw text. That's CLIP's job in an image generation pipeline: it reads the prompt and turns it into embeddings, a numerical representation that captures the meaning of the text in a form the rest of the model can condition its generation on. Without a text encoder like CLIP, there'd be no way for a written prompt to influence what a diffusion model produces.

How it works

CLIP, introduced by OpenAI, is a model made of two encoders trained together: an image encoder and a text encoder. According to Hugging Face's documentation, CLIP was trained by jointly training on 400 million (image, text) pairs, learning to project both images and their matching captions into the same shared embedding space, such that a correct image-caption pair ends up close together in that space and a mismatched pair ends up far apart: a training approach called contrastive learning. This lets CLIP generalize to concepts and categories it wasn't explicitly labeled on, since it learned meaning from natural language descriptions rather than a fixed list of class labels.

In a text-to-image pipeline, only CLIP's text encoder half is typically used at generation time: the prompt is tokenized, run through CLIP's text encoder, and the resulting embeddings are fed into the diffusion model's UNet at every denoising step to steer generation toward the prompt's meaning. Some pipelines also use CLIP's image encoder for image-based conditioning, as in tools like IP-Adapter.

Adult-AI use

Most users never interact with CLIP directly, but it's the reason prompt wording matters as much as it does in adult-AI image generation: how a phrase is embedded by CLIP affects how strongly and specifically the model responds to it. It also shows up as a visible setting in some local generation tools as "CLIP skip," which controls how many of CLIP's internal layers are used when generating the prompt embedding; skipping the last layer or two is a common technique with certain anime- and illustration-oriented checkpoints to change the character of the output.

How it differs from VAE

CLIP and the VAE are both standard components of a text-to-image pipeline, but they operate on entirely different problems. CLIP's job is turning text (and sometimes images) into meaning-carrying embeddings that condition what gets generated. The VAE's job is encoding and decoding between pixel images and the model's internal latent space; it has nothing to do with interpreting the prompt. A pipeline needs both: CLIP to understand what to generate, and the VAE to decode the result into a viewable image.

Limitations and misconceptions

  • CLIP is not the diffusion model itself; it doesn't generate images. It only produces the text (or image) embeddings that the separate diffusion model conditions on.
  • CLIP has a maximum prompt length (commonly 77 tokens in widely used checkpoints); text beyond that limit is typically truncated or requires special handling by the generation tool.
  • Because CLIP was trained on the concepts and language present in its training data, prompt terms outside that scope, or highly niche terminology, may not embed as distinctly as more common concepts.

Related terminology

Further reading