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.
Detailed answer & concept explanation~4 min readEverything 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. 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.
- OpenAI's tiktoken powers the BPE tokenizer behind GPT-5.5 and the o-series, with cl100k_base and o200k_base vocabularies.
- Google's SentencePiece is the tokenizer used by Gemini, T5, and many multilingual checkpoints because it handles whitespace as a regular symbol.
- Meta's Llama 4 uses a 128k-entry BPE tokenizer trained jointly on English and code corpora.
- HuggingFace tokenizers (the Rust library) is the de facto trainer for open-weight model releases on the Hub.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you choose vocab_size for a new LLM you are training from scratch?
QWhat changes if you switch from BPE to SentencePiece?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
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.
Same topic, related formats. Practice these next.