A glitch token is an entry in a tokenizer vocabulary that the model itself almost never encountered during training, so its embedding remains poorly learned and any prompt containing it can produce erratic, evasive or nonsensical behavior. In language models, which form a core part of artificial intelligence, glitch tokens are also called anomalous tokens, and they expose a quiet mismatch between the data used to build the tokenizer and the data used to train the network.
The phenomenon became widely known in early 2023, when researchers found that GPT-2 and GPT-3 era models could not repeat strings such as ” SolidGoldMagikarp”, a Reddit username that had become a single token. Instead of echoing it, the models substituted unrelated words, refused, or produced insults. The case turned glitch tokens into a standard example of tokenizer and training data misalignment.
How a glitch token arises
A glitch token arises when a string is frequent in the tokenizer corpus but rare in the model training corpus. Byte-pair encoding merges character sequences that appear often in the text it is fitted on, so a username repeated thousands of times in scraped forum logs can earn its own vocabulary slot. If that forum text is later filtered out or deduplicated before model training, the token survives in the vocabulary while its training signal nearly vanishes.
During training, every embedding row is updated only when its token appears in a batch. A token seen a handful of times or never keeps an embedding close to its random initialization, often shrunk toward the mean by weight decay. Such vectors tend to cluster near the centroid of the embedding space, where the network has learned no coherent meaning. When the model meets one of these vectors at inference time, downstream layers receive an input unlike anything they were optimized for.
The table below traces the typical chain of causes, from data collection to the visible symptom.
| Stage | What happens | Consequence |
|---|---|---|
| Tokenizer fitting | A string is frequent in the fitting corpus | The string becomes one vocabulary entry |
| Data filtering | Source pages are removed or deduplicated | The token almost disappears from training text |
| Model training | The embedding row receives few gradient updates | The vector stays near initialization |
| Inference | A prompt contains the token | Layers process an out-of-distribution input |
| Output | The model guesses from weak context | Substitution, refusal or incoherent text |
Typical symptoms in model output
The most reliable test is a repetition prompt: asking the model to repeat a string verbatim. A healthy token is echoed with near certainty, whereas a glitch token is often replaced by a different word, spelled out incorrectly, or avoided entirely. Because the model cannot represent the token, it often cannot generate it either, so its probability as an output stays extremely low.
Behavior varies between models and even between sampling settings, but researchers have documented a recurring set of patterns, summarized below.
| Symptom | Description | Likely cause |
|---|---|---|
| Substitution | The model outputs a related or random word instead | Embedding sits near unrelated tokens |
| Evasion | The model claims it cannot see or say the string | Weak representation triggers refusal patterns |
| Hallucinated meaning | The model invents a definition for the token | No grounded semantics were learned |
| Hostile or odd tone | Responses turn rude, comic or surreal | Unstable activations in later layers |
| Degenerate loops | Repetition or broken text follows the token | Sampling from a flattened distribution |
These symptoms resemble hallucination, but the mechanism differs. Hallucination usually reflects missing or conflicting knowledge, whereas a glitch token reflects a broken input representation at the very first layer of the network.
Glitch tokens compared with related token problems
Glitch tokens belong to a wider family of tokenization failures, and distinguishing them helps teams pick the correct fix. The comparison below places them next to concepts that practitioners often confuse with them.
| Concept | Core issue | Typical remedy |
|---|---|---|
| Glitch token | Vocabulary entry with an undertrained embedding | Retokenize or retrain with coverage |
| Unknown token | Input has no vocabulary match | Byte fallback or byte-level vocabulary |
| Special token | Control symbol such as end-of-sequence | Escape or strip from user input |
| Tokenization artifact | Odd splits harm spelling or arithmetic | Better merges or digit splitting |
| Adversarial suffix | Optimized token sequence steers the model | Input filtering and robust training |
The key distinction is that a glitch token is perfectly valid to the tokenizer. It passes every syntax check, maps to a known ID, and only reveals its defect when the model tries to interpret it.
Detecting glitch tokens in a vocabulary
Detection relies on inspecting model weights rather than waiting for odd answers. Teams with access to the weights can scan the whole vocabulary in minutes, while teams using a hosted API must rely on behavioral probes.
- Embedding norm analysis: undertrained rows often have unusually small norms or sit close to the mean embedding.
- Unembedding indicators: rows of the output matrix that never received positive gradients point in a shared, telltale direction.
- Repetition probes: candidate tokens are inserted into a verbatim echo prompt and flagged when the model fails.
- Training data counts: token frequencies in the training corpus reveal entries seen fewer than a few times.
A practical workflow combines weight indicators with behavioral verification. Weight-based screening ranks suspects cheaply, and the repetition test confirms which suspects actually break generation. Studies of open-weight models have found hundreds to thousands of suspect entries per vocabulary, with counts depending on vocabulary size and data pipeline.
Mitigation and practical risks
The most effective mitigation is to fit the tokenizer on the same distribution used for model training, or at least on a representative sample of it. Developers can also prune tokens with low training counts before pretraining begins, or merge them back into smaller subword pieces.
For deployed systems, the risks extend beyond strange answers. The following decision table links each situation to a recommended response.
| Situation | Recommended action | Reason |
|---|---|---|
| Training a new model | Align tokenizer and training corpora | Prevents undertrained rows at the source |
| Fine-tuning an open model | Add examples containing suspect tokens | Gives embeddings useful gradient signal |
| Serving a closed model | Filter or rewrite known glitch strings | Weights cannot be changed by the user |
| Security review | Test suspect tokens against safety rules | Anomalous inputs may bypass guardrails |
A real concern is that glitch tokens can destabilize safety behavior, because guardrails learned through fine-tuning also depend on reliable input representations. Evaluation suites therefore increasingly include vocabulary-level audits alongside prompt-level red teaming.
The idea in brief
A language model reads text in small pieces called tokens. Its list of pieces is built first, from one large pile of text. The model then learns from a second pile. Sometimes a piece appears often in the first pile but almost never in the second.
Such a piece is like a word in a dictionary that nobody ever taught you. You can see it, but it means nothing to you. When the model meets it, the model guesses wildly. It may swap it for another word, pretend it is not there, or answer strangely. That piece is a glitch token.
A practical scenario
A team at a software company fine-tunes an open-weight model for customer support. During testing, an engineer notices that tickets mentioning a specific legacy product code produce garbled replies or refusals, while all other tickets work well. The product code happens to be a single entry in the tokenizer vocabulary.
The engineer computes embedding norms across the vocabulary and finds that this entry sits among the smallest norms, close to the mean vector. A repetition prompt confirms the problem: the model cannot echo the code. The team adds about 2,000 support examples containing the code to the fine-tuning set. After retraining, the model repeats the code correctly and the garbled replies disappear. The team then adds a vocabulary audit to its standard release checklist.