The first step nobody sees
A text-to-image model never sees your words as you typed them. A tokenizer first cuts the text into tokens, pieces of words drawn from a fixed vocabulary learned from data. Common words are often a single token; rare words, names and words from less represented languages are split into several pieces. Most modern tokenizers use variants of byte pair encoding, a method adapted for language models by Sennrich and colleagues in 2016.
This has practical consequences. Many image models use text encoders with a hard token limit; the original CLIP encoder reads only 77 tokens, so long prompts may be silently cut. Languages that split into more tokens spend that budget faster and give the model less to work with, a disparity researchers have measured across dozens of languages.
The basics
A unit of text: a word, part of a word, a punctuation mark or a space.
A fixed list of tokens learned from training data, often tens of thousands of entries.
Repeatedly merging the most frequent character pairs into larger tokens, so common strings become single units.
Each token becomes a vector; the model builds meaning from these pieces.
Effects on prompts
A rare word like 'chiaroscuro' may become several pieces, each carrying weaker meaning.
Artist and place names break into fragments that can pull in unrelated associations.
With a 77-token encoder, everything past the limit can be ignored; front-load what matters.
Commas, brackets and line breaks are tokens too; some tools give them special roles, such as weights.
Languages and tokens
The same sentence can need several times more tokens in some languages than in English.
Non-Latin scripts are often split character by character or byte by byte.
More fragments mean the model has to assemble meaning from smaller, vaguer pieces.
Researchers have shown this makes models costlier and weaker for many languages.
Writing with tokens in mind
Put the subject and essential look early, in case the end is cut.
'Hazy' over a rare synonym, unless the rare word carries a meaning you need.
Follow a rare or foreign word with a short plain description.
Check whether your model uses a short-limit encoder or a long-context language model; it changes how long a prompt can usefully be.
The words to describe it
Precise words for the qualities above. Combine a few of them instead of naming the style or artist alone.
- token
- tokenizer
- vocabulary
- byte pair encoding
- subword
- token limit
- truncation
- front-loading
- tokenisation disparity
- embedding
A front-loaded prompt for a short-limit encoder: 'Chiaroscuro portrait (one hard candle light, deep shadow): an old woman sewing at night, warm skin, dark room.' The rare term is explained right away and everything important comes first.
How to put it into words
- Assume the end of a long prompt may be ignored.
- Pair rare words and names with plain descriptions.
- Expect other languages to spend the token budget faster.
Where we usually get it wrong
Writing ever longer prompts and assuming every word counts. With short-limit encoders the tail is simply dropped, and even with longer encoders, many weak tokens dilute strong ones. Concise and front-loaded beats long and scattered.
Use a free online tokenizer tool to paste the same prompt in English and in another language. Count the tokens for each, then see which words are split into many pieces. Rewrite the prompt so the split words are explained in plain terms.
Sources and further reading
- Sennrich, Haddow and Birch, 'Neural Machine Translation of Rare Words with Subword Units' (ACL 2016).
- Radford et al., 'Learning Transferable Visual Models From Natural Language Supervision' (CLIP, 2021).
- Petrov et al., 'Language Model Tokenizers Introduce Unfairness Between Languages' (NeurIPS 2023).