Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Subword tokenization keeps vocab compact, handles unseen words by splitting them into known pieces, and keeps sequences short enough for attention to stay cheap.
Imagine teaching a robot to read English. One option is to give it a dictionary with every word in it. That dictionary would be huge, and the moment someone types a brand new slang word, the robot is stuck. Another option is to teach the robot one letter at a time. Now the robot knows everything, but a single sentence becomes hundreds of pieces and the robot gets tired before it reaches the end. Subword tokenization, which is what BPE does, splits text into common chunks like 'token', 'ization', and 'un'. Common words stay as one chunk, weird new words get broken into pieces the robot already knows, and the input stays short enough to think about.
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: word vs char failure modes + BPE merge mechanics + vocab-size knob + production tokenizers (tiktoken, SentencePiece) + 2026 multilingual and digit gotchas.
import tiktoken
# cl100k_base is the BPE vocab used by GPT-4 family models
enc = tiktoken.get_encoding("cl100k_base")
text = "Tokenization is the first layer of every LLM."
ids = enc.encode(text)
print(len(text), "chars ->", len(ids), "tokens")
print([enc.decode([i]) for i in ids])
# Common words stay whole, rare patterns split.
# 'Tokenization' is one token; an unseen word like 'flibbertigibbet'
# would split into several known subwords.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.
Treating BPE as a compression trick rather than the contract that determines how every downstream layer perceives the input text.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.