M/Visual Library
  1. Visual Library
  2. Gen AI
  3. Compositionality: Why Models Mix Things Up

Gen AI

Compositionality: Why Models Mix Things Up

Why 'a red cube and a blue sphere' comes out swapped: compositional meaning, attribute binding, counting, spatial relations and negation, and how to write around them.

Also known as: compositionality in text-to-image, attribute binding, why AI mixes up colours and objects, spatial relations in prompts, counting in AI images

The meaning of the whole

The principle of compositionality, associated with the philosopher Gottlob Frege, says that the meaning of a sentence comes from the meanings of its parts and the way they are combined. 'The dog bites the man' and 'the man bites the dog' use the same words and mean opposite things. Humans handle this effortlessly.

Text-to-image models often don't. They are good at knowing which things belong in a picture and weaker at how those things relate: which colour belongs to which object, how many there are, what is left of what. Benchmarks such as Winoground and T2I-CompBench were built to measure exactly this, and while newer models with stronger language encoders do better, composition remains one of the clearest gaps between reading words and understanding a sentence.

Where composition fails

Attribute binding

'A red cube and a blue sphere' gives a blue cube, two red objects, or purple everywhere.

Counting

'Seven candles' gives five or nine; exact numbers above three or four are unreliable.

Spatial relations

Left and right, behind and in front, on and under are often swapped or ignored.

Object neglect

With several subjects, one may simply disappear; the model attends to some words more than others.

Why it happens

Bag-of-words behaviour

Some text encoders behave as if word order barely matters, keeping which words appear but losing how they connect.

Caption habits

People rarely caption images with exact counts or positions, so models saw little training signal for them.

Attention leakage

A colour word can attend to several image regions at once and spread across objects.

Rare combinations

An unusual pairing, a green banana-shaped lamp, has few examples, so the model drifts back to typical ones.

How to write around it

Keep attributes next to their nouns

'A red ceramic cube beside a blue glass sphere', never scattered adjectives.

One relation per sentence

Describe the layout in short clauses: 'On the left, a red cube. On the right, a blue sphere.'

Small numbers, or arrangements

Prefer 'three' to 'seven', or describe a shape: 'a row of candles along the shelf'.

Promote neglected objects

Move a missing object earlier, give it more description, or generate it separately.

When words aren't enough

Layout control

Sketches, bounding boxes, depth maps or pose guides fix composition directly.

Regional prompting

Some tools let you prompt each area of the image separately.

Inpainting

Fix one object's colour or position in place instead of regenerating everything.

Stronger language encoders

Models built on large language models handle relations better; test the same prompt across tools.

The words to describe it

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

  • principle of compositionality
  • attribute binding
  • attribute leakage
  • spatial relation
  • counting error
  • object neglect
  • bag-of-words encoder
  • word order sensitivity
  • regional prompting
  • layout control
A description to start from

Instead of 'red blue cube sphere on table': 'On a white table: on the left, a small red ceramic cube; on the right, a larger blue glass sphere. Nothing else on the table.'

How to put it into words

  • Attach every attribute directly to its noun.
  • State positions in short, separate clauses.
  • Keep counts small or describe an arrangement instead.

Where we usually get it wrong

Assuming the model 'didn't listen' when it swaps colours or loses an object. It read every word; what it failed at was the grammar connecting them. Rewriting the sentence structure helps more than repeating the word.

Try this

Write 'a yellow umbrella to the left of a green bicycle, three pigeons on the ground'. Generate it four times and note every binding, position and counting error. Then rewrite it with attached attributes and short clauses, and compare.

Sources and further reading

  • Thrush et al., 'Winoground: Probing Vision and Language Models for Visio-Linguistic Compositionality' (CVPR 2022).
  • Huang et al., 'T2I-CompBench: A Comprehensive Benchmark for Open-world Compositional Text-to-image Generation' (NeurIPS 2023).
  • Chefer et al., 'Attend-and-Excite: Attention-Based Semantic Guidance for Text-to-Image Diffusion Models' (SIGGRAPH 2023).

Keep looking