Skip to content
AI.info

Generative AI

Tokens, Tokenizers, and the Boundaries a Model Sees

Understand how tokenization converts raw input into model units and how vocabulary choices affect cost, multilingual behavior, and reliability.

By the end you can

Example

The same text, up to fifteen times longer in another language

The same text, translated, can cost fifteen times more to send to a model. That was measured, not estimated. Four researchers took identical text in several languages and counted what each version cost in tokens. The paper is called "Language Model Tokenizers Introduce Unfairness Between Languages", and it appeared at NeurIPS in 2023. Its abstract states the spread without hedging: “The same text translated into different languages can have drastically different tokenization lengths, with differences up to 15 times in some cases.”

The obvious remedies do not close the gap. The same abstract continues: “These disparities persist even for tokenizers that are intentionally trained for multilingual support. Character-level and byte-level models also exhibit over 4 times the difference in the encoding length for some language pairs.”

A limit expressed in tokens is therefore not one limit. It is a different limit per language, hidden behind a single number in the documentation. Two users can send the same document, to the same product, under the same stated context window. Only one of them gets truncated.

  • Segmentation: A visually short string can fragment into many learned pieces — translations of identical text differed in tokenized length by up to 15 times.
  • Normalization: Visually similar Unicode sequences may follow different token paths, which is why the four normalization forms — NFD, NFC, NFKD and NFKC — sit upstream of the vocabulary.
  • Budget: Instructions, examples, retrieved text, and output all compete for the same context allocation, so a fifteenfold segmentation penalty is spent out of a fixed allowance.
  • Cost: Billing and latency track tokens more closely than characters or words; on XLSUM, combined prompting and generation cost ran up to 4x higher in Telugu and Amharic.
  • Evaluation: Average English inputs conceal the worst-case scripts and identifiers, and the disparity survives even in tokenizers built deliberately for multilingual support.

A token is an implementation unit, not a linguistic promise

A tokenizer maps text or other serialized input into discrete IDs from a vocabulary. Common systems use subword pieces, bytes, or combinations that balance vocabulary size, sequence length, and coverage. The resulting pieces may align with a word, part of a word, punctuation, whitespace, or raw bytes. A token boundary does not prove a semantic boundary. The same visible text can tokenize differently across models.

Numbers are where that stops being an abstraction, because there the boundary changes the answer. The field does not even agree on where a number ends. Singh and Strouse open their 2024 paper on arithmetic in frontier models by listing the disagreement: “With the increased use of LLMs for reasoning, various number-specific tokenization schemes have been adopted, with popular models like LLaMa and PaLM opting for single-digit tokenization while GPT-3.5 and GPT-4 have separate tokens for each 1-, 2-, and 3-digit numbers.”

The chunking is not cosmetic. Comma-separating numbers at inference time forces right-to-left tokenization, and Singh and Strouse report that this raises arithmetic accuracy by up to 20%. The arithmetic did not change and the model did not change. Only the boundaries did.

Tokenization determines what the model receives and how much context the input consumes.

Comparison

Subword vocabularies and byte-level coverage solve different problems

No tokenizer is uniformly best across languages, code, noise, and deployment constraints. Each of the three approaches has a published measurement behind it.

Subword vocabulary. Frequent strings become compact reusable pieces, so the vocabulary encodes corpus frequency. What the training data said often is cheap. Rare forms fragment. The cost is measurable and it is per language: over the mC4 pre-training corpus, mT5's subword tokenizer compresses at 4.1 bytes per SentencePiece token overall. That average hides a range from 2.5 bytes per token for Maltese to 9.0 for Khmer.

Byte-oriented representation. ByT5 threw the subword vocabulary away. Its 2022 paper says what replaced mT5's SentencePiece pieces: “The bytes are embedded to the model hidden size using a vocabulary of 256 possible byte values.” The remainder of the vocabulary is three entries. “An additional 3 IDs are reserved for special tokens: padding, end-of-sentence, and an unused <UNK> token that we include only for convention.” No input is unrepresentable. The sequences get longer.

Domain-specialized vocabulary. Compactness inside one field is paid for with compatibility outside it. SciBERT built SCIVOCAB — a 30K WordPiece vocabulary trained with SentencePiece over 1.14M Semantic Scholar papers, 3.17B tokens, 18% computer science and 82% biomedical — and set it against BERT's general-domain BASEVOCAB. Two vocabularies of the same size, built the same way, on different text. The 2019 paper reports what came out: “The resulting token overlap between BASEVOCAB and SCIVOCAB is 42%, illustrating a substantial difference in frequently used words between scientific and general domain texts.” Migrating between them is not a preprocessing change. It changes which strings are cheap and which embeddings mean anything.

FigureComparison · 3 columns

Subword vocabulary

Frequent strings become compact reusable pieces.

  • Often efficient on training-domain text
  • Vocabulary encodes corpus frequency
  • Rare forms may fragment heavily
  • Migration changes prompt and embedding behavior

Byte-oriented representation

Any byte sequence can be represented without an unknown token.

  • Strong coverage for arbitrary input
  • Sequences can become longer
  • Visual characters may span several bytes
  • Useful for noisy or multilingual data

Domain-specialized vocabulary

Technical terms and identifiers receive more compact representations.

  • Can reduce length in a narrow domain
  • Requires new training or adaptation
  • May weaken compatibility with general models
  • Needs drift monitoring as terminology changes

Visual

Text passes through more than one boundary

A product should record each transformation before the model sees an ID sequence. Raw bytes arrive from files, forms, APIs, or user devices. An encoding such as UTF-8 turns them into code points. The product may normalize the text and insert roles, separators, or tool schemas. The deployed vocabulary maps that serialized input to discrete IDs. Context packing then decides which tokens survive truncation and how the remaining space is allocated.

The normalization stage is a specified step, not a local convention. Unicode Standard Annex #15, "Unicode Normalization Forms", defines exactly four: NFD, NFC, NFKD and NFKC. RFC 5198 named the one expected on the wire back in 2008: “Before transmission, all character sequences SHOULD be normalized according to Unicode normalization form "NFC" (see Section 3).”

When two services in the same pipeline pick different forms, or one picks none, the same visible string reaches the tokenizer as different code points and leaves it as different IDs. The stage that made the difference is upstream of everything the model logs.

FigureProcess · 5 steps
  1. 1

    Raw bytes

    The application receives encoded data from files, forms, APIs, or user devices.

  2. 2

    Unicode decoding

    Bytes become code points under an encoding such as UTF-8.

  3. 3

    Normalization and templating

    The product may normalize text and insert roles, separators, or tool schemas.

  4. 4

    Tokenization

    The deployed vocabulary maps the serialized input to discrete IDs.

  5. 5

    Context packing

    The application chooses which tokens survive truncation and how space is allocated.

Key idea

Token counts create hidden product policies

Truncation is not a neutral detail for engineering to settle on its own. Keeping the beginning of a document can remove the signed conclusion. Keeping the end can remove definitions and exceptions. A model upgrade can also change the tokenizer, and then prompts, retrieved chunks, stop sequences and cost estimates all behave differently. Tokenizer version belongs in release evidence.

That the vocabulary is a separate artifact with its own defects is documented, not hypothetical. Land and Bartolo, at Cohere, went looking for tokens that exist in a vocabulary but were barely or never trained. They found them everywhere they looked. Their paper, "Fishing for Magikarp: Automatically Detecting Under-trained Tokens in Large Language Models", was named an Outstanding Paper at EMNLP 2024. It reports: “Even with our relatively conservative threshold for verification, we detect the presence of such tokens across all tested models, with typically around 0.1–1% of the vocabulary consisting of severely under-trained tokens, although their prevalence varies significantly.”

In Cohere's own Command R and R+ they found over 1,400 manually added emoji tokens that were unreachable and clearly untrained. An entry can sit in the vocabulary, be counted in the vocabulary size, and be billed for if a user manages to produce it. It can still correspond to nothing the model ever learned.

A context budget is a policy about which information the model is allowed to see.

Case

Two vocabularies an order of magnitude apart

Vocabularies differ across models by an order of magnitude, and the difference is not cosmetic. GPT-2 shipped with 50,257 tokens and a context of 1,024, raised from 512. Llama 3 combines 100,000 tokens from the tiktoken tokenizer with 28,000 more added to better support non-English languages, reaching 128,000. Byte-pair encoding, the algorithm underneath both, arrived in 2016 as a way to handle rare words in machine translation. A token budget written against one of these vocabularies is wrong against the other. Nothing in the visible text tells you which one you are counting against.

Figure

A token budget written against one vocabulary is wrong against the other: what 128,000 tokens is made of, and what GPT-2 shipped with.

Steps

Run a tokenizer audit before setting limits

Use production-like data rather than a handful of demonstration prompts. Sample real inputs across languages, code, identifiers, OCR noise, and long documents. Measure the distributions: tokens per character, per word, and per task component. Inspect fragmentation to find the names, terms, and scripts with extreme token counts. Test truncation policies by measuring which facts disappear under realistic packing. Then version the tokenizer, tying counts, prompts, embeddings, and regressions to the exact release.

The measurement step has a published worked example. Seven researchers ran it over OpenAI's API for 22 typologically diverse languages in 2023, in a paper titled "Do All Languages Cost the Same? Tokenization in the Era of Commercial Language Models". Some languages need 5 times as many tokens to convey the same information. On XLSUM, the combined prompting and generation cost ran up to 4x higher in Telugu and Amharic. The paper puts the finding in the currency a user actually pays in: “While LMs like ChatGPT might perform tasks in Telugu, for example, a user in Andhra Pradesh might pay 5× more than an English user in the US for an equivalent use of the model.”

An audit that reported a single average tokens-per-character figure would have surfaced none of that. The spread across the 22 languages is the finding. The mean is what hides it.

FigureProcess · 5 steps
  1. 1. Sample real inputs

    Include languages, code, identifiers, OCR noise, and long documents.

  2. 2. Measure distributions

    Report tokens per character, per word, and per task component.

  3. 3. Inspect fragmentation

    Find names, terms, and scripts with extreme token counts.

  4. 4. Test truncation policies

    Measure which facts disappear under realistic packing.

  5. 5. Version the tokenizer

    Tie counts, prompts, embeddings, and regressions to the exact tokenizer release.

The tokenizer quietly shapes every later layer

Embeddings are learned for token IDs, attention operates over token positions, and serving cost grows with tokenized sequences. Retrieval systems depend on token-aware chunking and context packing too. Each measurement above lands in a different layer. The normalization form decides which code points arrive. The vocabulary decides how many pieces they become. The 0.1–1% of severely under-trained entries decides whether some of those pieces mean anything. The digit boundaries decide whether a sum comes out right.

Treat tokenization as part of the application contract. A tokenizer change is not merely a preprocessing refactor when it changes cost, truncation, or model behavior. The published record shows it changes all three.

Key takeaways