Tokenizer compression
Why Engram merges vocabulary entries that normalize to the same text before hashing, and how much that shrinks real vocabularies.
“Apple”, “ apple”, “APPLE”
BPE vocabularies are full of near-duplicates: the same word with and without a leading space, capitalized, all caps, with an accent. To the model they are different ids, so an n-gram table keyed on raw ids would learn “the Apple” and “the apple” separately - and see each one less often.
Engram collapses them first. The paper describes a surjective map from the vocabulary V to a smaller V′, “based on normalized textual equivalence”. The demo code does it with Hugging Face normalizers, verbatim:
13 raw tokens → 4 compressed ids (69% fewer)
- id 0“apple”←Apple␣appleAPPLE␣Äpple
- id 1“pear”←pear␣Pear␣PEAR
- id 2“file”←file␣file
- id 3“␣”←↵␣␣␣⇥
Quick check
Which of these end up as the same compressed id?
How much does it compress?
We ran the demo's normalizer over two real vocabularies, once in Python with the tokenizers library and once with Hyperfield's hf.text.compressVocab. Both gave the same lookup table, id for id:
| TOKENIZER | ENTRIES | COMPRESSED IDS | REDUCTION |
|---|---|---|---|
| DeepSeek-V3 (tokenizer.json, incl. added tokens) | 128,815 | 98,627 | 23.44% |
| Yumon (8k BPE, already lowercased) | 8,192 | 7,268 | 11.28% |
The paper reports 23.43% for its 128k tokenizer, and the biggest groups match it: the space (163 vocabulary entries become “ ”), then “a” (54), “o” (40), “e” (35) and “i” (30). Yumon's tokenizer already lowercases its input and still loses 11%, mostly to leading-space variants such as “cat” and “ cat”.
Quick check
Where does the compressed id get used?