M/Visual Library
  1. Visual Library
  2. Gen AI
  3. Text-to-Image Semantics

Gen AI

Text-to-Image Semantics

What happens to your words inside a text-to-image model: tokens, embeddings, image-caption training and attention, and why models struggle with counting, negation and space.

Also known as: how text-to-image models understand prompts, text to image semantics, how AI reads prompts

From words to pixels

Text-to-image models learn from huge collections of images paired with captions, often scraped from the web, such as the LAION-5B dataset. A text encoder turns your prompt into tokens and then into vectors, lists of numbers that place words in a space of meaning. Models like Stable Diffusion used OpenAI's CLIP text encoder; others, like Google's Imagen, used large language models such as T5.

The image itself is usually made by diffusion: starting from noise and removing it step by step, guided by the text. At each step, cross-attention links parts of the prompt to parts of the image. Knowing this explains a lot of everyday behaviour: why some words dominate, why long prompts get cut, and why models still struggle with things that are easy in language, like 'three' or 'not'.

The pipeline

Tokens

Pieces of words the model reads; rare words and non-Latin scripts often split into many tokens.

Embedding

A vector that places a token or a prompt in a space where similar meanings are close.

Text encoder

The part that understands the prompt, like CLIP or a language model.

Diffusion

Generating an image by gradually removing noise, guided by the text.

Cross-attention

The mechanism linking words to regions of the image.

Guidance scale

How strongly the image follows the prompt versus looking natural.

What it learned from

Image-caption pairs

Models learn from how people captioned images online, with all their habits and gaps.

Alt text and captions

Much of the training text was written for other purposes, often short and plain.

Defaults

When a prompt is vague, the model fills gaps with the most common pattern it saw.

Prompt rewriting

Some systems, like DALL·E 3, rewrite your prompt into a longer one with a language model before generating.

Typical blind spots

Counting

'Seven birds' often gives five or nine.

Negation

'No' and 'without' can bring the very thing into the image.

Spatial relations

Left, right, behind and on top of are often confused.

Attribute leakage

Colours or materials move from one object to another.

Text in images

Writing has improved but is still fragile, especially in Persian and other right-to-left scripts.

Token limits

Older encoders read only a limited number of tokens (77 for CLIP); later words may be ignored.

Words to describe Text-to-Image Semantics

Precise words for the qualities above. Combine a few of them instead of naming the style or artist alone.

  • tokens
  • text embedding
  • CLIP text encoder
  • diffusion denoising
  • cross-attention
  • guidance scale
  • image-caption training data
  • default patterns
  • attribute leakage
  • token limit
A description to start from

Instead of 'a room with no windows and three lamps on the left of a blue chair', try: 'A windowless room with solid walls. A blue chair in the centre. Three brass lamps stand together to the left of the chair.'

How to describe Text-to-Image Semantics in words

  • Put the essential subject early and in plain words.
  • Describe what is present instead of what is absent.
  • Keep each object and its attributes together, and simplify spatial relations.

Where we usually get it wrong

It is tempting to think the model 'understands' like a person. It matches patterns between words and images it has seen. That's why describing images in the way good captions do, concrete, visual and specific, works better than abstract instructions.

Try this

Write a prompt with three objects of different colours in a specific arrangement. Generate several images and note every error: swapped colours, wrong positions, missing objects. Rewrite the prompt to reduce each one.

Keep looking