Code-heavy tokenizer corpora can improve syntax packing but hurt what elsewhere?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Code-heavy tokenizer corpora can improve syntax packing but hurt what elsewhere?
Code-heavy tokenizer training can improve code token efficiency but worsen tokenization for rare natural-language patterns and low-resource languages.
Imagine a suitcase with fixed space. If you pack more tools for coding tasks, your travel clothes fit less neatly. A tokenizer works similarly: it has a fixed vocabulary budget. Giving more slots to code symbols and identifier chunks helps code compression, but some language pieces outside code lose dedicated space. Those parts then split into more tokens and become harder to model efficiently.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: finite vocabulary budget + domain fragmentation metric + why code gains can mask non-code regressions.
from tokenizers import Tokenizer
from tokenizers.models import BPE
from tokenizers.trainers import BpeTrainer
tok = Tokenizer(BPE(unk_token="<unk>"))
trainer = BpeTrainer(
vocab_size=32000,
special_tokens=["<unk>", "<pad>", "<s>", "</s>"],
)
# 70% code + 30% natural text shifts merge priorities toward code symbols
tok.train(["corpus/code.txt", "corpus/natural.txt"], trainer)
def tokens_per_byte(text: str) -> float:
ids = tok.encode(text).ids
return len(ids) / max(len(text.encode("utf-8")), 1)
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
A common mistake is celebrating better code packing without checking whether non-code token fragmentation and quality got worse.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.