Foundations to Frontier
Tests

Tokenizer Effects on Model Behavior

A language model never sees letters or digits directly, only token identities, and many familiar LLM failures come from this. Counting letters in a word, reversing strings, spelling, arithmetic, rhyming and handling of leading spaces all depend on how text was split. Numbers are a prominent case: BPE chunks digits inconsistently ('12345' becomes '12', '34', '5'), so place value is not aligned across numbers, which is why many newer models split every digit. Tokenizers also create under-trained 'glitch' tokens, cost differences between languages, and prompt-boundary artefacts. This page covers these effects and the design choices that mitigate them. In the exercises you split digits, count letters from token spellings and find under-trained tokens. You then measure how the number tokenisation affects learning the last digit of a sum with a simple per-token learner. With single-digit tokens it reached 1.00 accuracy, against 0.42 for BPE (214 different last tokens) and 0.36 or 0.14 for 3-digit chunks. The price is length: single digits used 3.62 tokens per number against 1.59 for 3-digit chunks.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Why models stumble on spelling and sums

If you only ever saw words as whole puzzle pieces, it would be hard to say how many r’s are in “strawberry”: you would have to remember each piece’s spelling. Language models are in exactly this position. Numbers are worse: “12345” might be cut as “12” + “34” + “5”, but “1234” as “1234”, so the ones digit is not always in the same place. Splitting numbers into single digits makes arithmetic easier, at the cost of longer inputs. The demo shows how one sentence is cut into tokens.

Language lab
"the newest rockets flew lower": 29 characters, 5 words, 20 subword tokens after 6 BPE merges (t·h·e ne·we·st r·o·c·k·e·t·s f·l·e·w lo·we·r). Subwords sit between: no unknown words, shorter than characters.
Why engineers care

Telemetry values, part numbers, coordinates and units flow through LLMs in engineering assistants. Knowing how numbers are tokenised explains odd arithmetic errors and argues for tools (calculators, code) instead of mental arithmetic.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A model sees text as…
  2. 2. Counting letters is hard because…
  3. 3. Many newer models split numbers into…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Spelling and character tasks: letters inside a token are not directly visible; the model must memorise each token’s spelling. Errors on letter counting, reversal or anagrams are tokenisation effects.
  • Numbers: BPE learns frequent digit strings (years such as “2024”, round numbers), so the same digit positions fall in different tokens in different numbers. Schemes:
    • single digits (LLaMA, Mistral): about one token per digit, aligned place values;
    • chunks of up to 3 digits (GPT-4 style): 1110 number tokens, shorter sequences;
    • right-to-left chunking, which aligns place values from the units digit.
  • Leading spaces: “▁dog” and “dog” are different tokens; a prompt ending with a space can push the model into rare tokens (the fix is called token healing).
  • Under-trained tokens: tokens learned by the tokenizer but rare or absent in model training (“SolidGoldMagikarp”) have untrained embeddings and cause bizarre outputs.
  • Cost and fairness: languages and domains with more tokens per word get less effective context and higher price.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Distinct tokens for all 1- to 3-digit strings:
  2. 2. A token learned by the tokenizer but absent from training data has…
  3. 3. Single-digit tokenisation makes numbers…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Tokenizer effects in code

Exercise 1.

  • Split digits individually.
  • Count letters given only the tokens’ spellings.
  • Find token boundary positions to compare segmentations.

Practice.

  • Inspect tokenisation of your critical inputs (numbers, identifiers, units) with the model’s tokenizer before building prompts or fine-tuning sets.
  • Avoid trailing spaces in prompts; let the model produce the space as part of the next token.
  • For arithmetic, counting or exact string manipulation, have the model call a tool or write code.
  • When training a tokenizer, split digits (pre-tokenisation regex) and check for tokens that are rare in the model’s training data.
from transformers import AutoTokenizer
for name in ["gpt2", "meta-llama/Llama-2-7b-hf"]:
    tok = AutoTokenizer.from_pretrained(name)
    print(name, [tok.convert_ids_to_tokens(tok(x, add_special_tokens=False)["input_ids"]) for x in ["12345", "1234", " strawberry"]])
🐍 Exercise 1: digits, letters and boundaries
Split digits, count letters from token spellings and list token boundary positions.
📝 Quick check (Level 2)
0/3 answered
  1. 1. For exact arithmetic, an LLM should…
  2. 2. Prompts should usually avoid…
  3. 3. Before fine-tuning on numeric data, inspect…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Information is present but not exposed. A token sequence determines the text exactly, so in principle a large enough model can recover any character-level fact. But the mapping from token identities to characters must be learned separately for every token, from indirect evidence. Tasks that need character information get harder as tokens get longer and more numerous.

Alignment of structure. Arithmetic depends on aligned place values. With single digits, the units digit is always the last token and carries are local. With variable BPE chunks, the same digit position sits inside different tokens, so the model must learn a separate mapping for each chunk and combine misaligned pieces. Studies of arithmetic in LLMs (e.g. Singh and Strouse, 2024) find large accuracy differences between left-to-right and right-to-left number chunking.

Sharing vs sparsity. A neural model shares statistical strength through embeddings, so it suffers less than a pure lookup table. But the direction of the effect is the same: more, rarer and less consistent tokens need more data.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Character information in tokens is…
  2. 2. Arithmetic needs…
  3. 3. Neural models share strength through…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How does number tokenisation affect learning a digit-level rule?

History.

  • H. Touvron et al., “LLaMA” (2023), splitting digits individually.
  • J. Rumbelow and M. Watkins, “SolidGoldMagikarp” (LessWrong, 2023), on glitch tokens.
  • A. K. Singh and D. J. Strouse, “Tokenization counts: the impact of tokenization on arithmetic in frontier LLMs” (2024).

Exercise 2.

  • Numbers as in text: 1–6 digits on a log-uniform scale, plus 15% years and 15% round numbers.
  • Tokenisations:
    • single digits;
    • 3-digit chunks from the left;
    • 3-digit chunks from the right;
    • BPE with 300 merges learned on 20,000 such numbers.
  • Task: predict (a + b) mod 10 from the last token of each operand, using a count table learned from 2000 training pairs (unseen pairs fall back to the most common answer). The table is a deliberately simple learner with no sharing between tokens.
tokenisation tokens per number distinct last tokens last token is one digit last-digit accuracy test pairs seen in training
single digits 3.62 10 1.000 1.000 1.000
3-digit chunks (left) 1.59 512 0.441 0.361 0.282
3-digit chunks (right) 1.59 752 0.125 0.144 0.042
BPE (300 merges) 1.95 214 0.393 0.417 0.343
  • BPE segmentations: “1999” → [1999], “2024” → [2024], “12345” → [12, 34, 5], “500000” → [50, 0, 000].
  • Single digits make the rule trivial: 10 last tokens, 100 table cells, all seen in training, perfect accuracy.
  • Chunked digits scatter the information: the units digit hides inside hundreds of different last tokens, most pairs are unseen with 2000 examples, and accuracy falls to 0.14–0.42.
  • The cost is length: single digits need 3.62 tokens per number against 1.59 for 3-digit chunks.
  • Right-to-left chunks did worst here because their last token is almost always a full 3-digit chunk. That does not contradict findings that right-to-left chunking helps full addition, where aligning all place values matters more than the size of the last token.
  • Caveat: a neural model shares information across tokens through embeddings, so the gaps would be smaller. The direction is the same.
  • Seeds: seed 1 gave 1.00, 0.435 (BPE), 0.377 and 0.169.
🐍 Exercise 2 (research): how does number tokenisation affect learning a digit-level rule?
Tokenise numbers with single digits, 3-digit chunks and BPE, and learn the last digit of a sum from the operands' last tokens.

Tokenizer effects in AI, robotics and aerospace

  • Engineering assistants: delegate arithmetic on telemetry and unit conversions to tools rather than trusting token-level arithmetic.
  • Identifiers: check how part numbers, NOTAM codes and call signs split before fine-tuning.
  • Design lesson: if a task depends on characters or digits, make them visible in the tokenisation or give the model a tool.

References

  1. H. Touvron et al. (2023). “LLaMA: open and efficient foundation language models.” arXiv:2302.13971.
  2. A. K. Singh and D. J. Strouse (2024). “Tokenization counts: the impact of tokenization on arithmetic in frontier LLMs.” arXiv:2402.14903.
  3. S. Land and M. Bartolo (2024). “Fishing for Magikarp: automatically detecting under-trained tokens in large language models.” arXiv:2405.05417.