Skip to content
INDIE / MACHINE
CONCEPTLESSON 2 OF 65 MIN

Tokenizer compression

Why Engram merges vocabulary entries that normalize to the same text before hashing, and how much that shrinks real vocabularies.

STEP 1 / 4QUIZ 0 / 2
01 /

“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:

NFKC → NFD → StripAccents → Lowercase → [ \t\r\n]+ → “ ” → Strip
A lone space survives as a token: it is swapped for a sentinel before Strip and back after.
INTERACTIVE / TOKENIZER COMPRESSION

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“␣”←↵␣␣␣⇥
Each vocabulary entry is decoded, then normalized the way DeepSeek's demo does it: NFKC, NFD, drop accents, lowercase, collapse whitespace, strip. Entries with the same result share one id before hashing. Separate tokens with |, and type \n or \t for a newline or tab.
02 / CHECK YOURSELF

Quick check

Which of these end up as the same compressed id?

03 /

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:

TOKENIZERENTRIESCOMPRESSED IDSREDUCTION
DeepSeek-V3 (tokenizer.json, incl. added tokens)128,81598,62723.44%
Yumon (8k BPE, already lowercased)8,1927,26811.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”.

04 / CHECK YOURSELF

Quick check

Where does the compressed id get used?

LESSON 2 COMPLETE

Up next: Hashing n-grams into tables