tokenize.rs

EMNLP 2024 · arXiv 2405.05417

Fishing for Magikarp

Sander Land, Max Bartolo

🏆 Outstanding Paper Award, EMNLP 2024

Read the paper on arXiv ↗

Why does SolidGoldMagikarp break language models? It sits in the tokenizer but barely appears in the training data. This paper finds these glitch tokens automatically.

A mock chat: the user asks to fix a syntax error containing a glitch token, and the chatbot replies with garbled, nonsensical output.
A single under-trained token silently derails an otherwise ordinary request.

The problem

Tokenizers are built separately from models, so vocabularies fill with tokens the model almost never saw during training. These under-trained glitch tokens cause strange, unwanted behaviour, and there was no reliable way to find them beyond stumbling onto them.

What we do

Under-trained tokens leave a fingerprint in the model's own weights: their embeddings drift toward a shared, telltale direction. We combine these weight-based indicators with tokenizer analysis and a prompting step that confirms each candidate. On open models, the indicators track how often a token appeared in training across about ten orders of magnitude.

Most glitch tokens have oddly specific origins:

TokenWhere it came from
SolidGoldMagikarpA Reddit username that gave the phenomenon its name
BjKPZFqOne document full of base64-encoded strings (StarCoder2)
OstschwizertütschA list of Wordle answers by dialect (StarCoder2)
天天中彩票APPChinese lottery-app ad text (GPT-4o)
\uEFC0An unassigned private-use Unicode character (Mistral)

Why it matters

We scan around two dozen open models plus closed ones such as GPT-4 and Claude. Glitch tokens show up in all of them, from a handful in some to thousands in others, and the method surfaced real tokenizer bugs that vendors later fixed. Detecting them makes models safer and more efficient, and helps close the gap between tokenizer and training.

Read the paper on arXiv ↗ Glitch token gallery → Code on GitHub ↗