M/Visual Library
  1. Visual Library
  2. Gen AI
  3. Tokenisation: How Models Split Your Words

Gen AI

Tokenisation: How Models Split Your Words

Before a model reads a prompt, it cuts it into tokens. What tokens are, why rare words and some languages break into many pieces, why long prompts get cut off, and what that means for writing.

Also known as: tokenization in AI prompts, what is a token, CLIP 77 token limit, byte pair encoding, why long prompts get cut

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

Token

A unit of text: a word, part of a word, a punctuation mark or a space.

Vocabulary

A fixed list of tokens learned from training data, often tens of thousands of entries.

Byte pair encoding

Repeatedly merging the most frequent character pairs into larger tokens, so common strings become single units.

Embedding per token

Each token becomes a vector; the model builds meaning from these pieces.

Effects on prompts

Rare words split

A rare word like 'chiaroscuro' may become several pieces, each carrying weaker meaning.

Names split

Artist and place names break into fragments that can pull in unrelated associations.

Length limits

With a 77-token encoder, everything past the limit can be ignored; front-load what matters.

Punctuation and spacing

Commas, brackets and line breaks are tokens too; some tools give them special roles, such as weights.

Languages and tokens

Unequal cost

The same sentence can need several times more tokens in some languages than in English.

Scripts

Non-Latin scripts are often split character by character or byte by byte.

Less meaning per token

More fragments mean the model has to assemble meaning from smaller, vaguer pieces.

Fairness

Researchers have shown this makes models costlier and weaker for many languages.

Writing with tokens in mind

Front-load

Put the subject and essential look early, in case the end is cut.

Prefer common words where they mean the same

'Hazy' over a rare synonym, unless the rare word carries a meaning you need.

Explain rare terms

Follow a rare or foreign word with a short plain description.

Know your tool

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 description to start from

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.

Try this

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).

Keep looking