BPE tokenization makes high-entropy secrets easy for code LLMs to memorize
Byte-Pair Encoding tokenization creates a ‘gibberish bias’ that lowers token-level entropy and increases secret memorization in code LLMs
AI/ML arXiv 20 Apr 2026 Measurement Simulation evidence
Published as “Understanding Secret Leakage Risks in Code LLMs: A Tokenization Perspective”
Why it matters
Tokenizer design choices can materially affect secret leakage risk in code LLMs, so developers and model builders should consider entropy-aware tokenization or mitigation strategies.
Summary
The paper shows that secret strings tokenized with BPE have a long-tailed token distribution, yielding a KL divergence of 2.668 versus a typical code corpus, which indicates a strong distribution shift and low token-level entropy (gibberish bias). Experiments with larger vocabularies (≈39k, 62k, 94k tokens) reveal that this bias becomes more pronounced as tokenizer size grows. The evidence is based on analyses of a secret dataset and a Stack V2 code corpus, comparing token frequency, entropy, and KL divergence, but the study is limited to three Code LLMs and only BPE tokenizers.
What they found 4
- Secret token distribution is long-tailed and low-entropy, confirming gibberish bias.
“Using a CLLM tokenizer, the token distribution of secret data is long-tailed - and such a long-tailed distribution explains the low entropy of secrets, hence explains the claimed gibberish bias.”
- KL divergence between secret dataset and code corpus is 2.668, indicating a significant distribution shift.
“Setting the Stack V2 as the reference data distribution, we further report the KL divergence between the secret dataset and the Stack V2. The resulting KL divergence is 2.668, demonstrating the discrepancy.”
- Larger tokenizer vocabularies increase the magnitude of gibberish bias.
“Gibberish bias tends to be more pronounced in models employing larger tokenizer vocabularies.”
- Secrets have lower token-level entropy but higher character-level entropy compared to non-secrets, achieving near-maximal normalized entropy.
“secrets exhibit lower entropy at the token level and higher entropy at the char level; secrets achieve almost maximal normalized entropy.”
Caveats 3
- Limited by space, this paper fails to enumerate all choices of CLLMs since there are too many.
- We focus on BPE, since it is the dominant tokenization strategy in the community.
- We left further investigation on Unigram and WordPiece for future research.
What’s new here 4
- Identifies a tokenization-induced “gibberish bias” that lowers token-level entropy of secret strings, increasing memorization risk.
- Quantifies the distribution shift between secret data and typical code training data using KL divergence (2.668).
- Demonstrates that larger tokenizer vocabularies exacerbate the bias.
- Discusses mitigation directions and broader implications for tokenizer design.