Skip to content
mentoor

Tokenizers (BPE)

For engineers

How byte-pair encoding builds a vocabulary, how real tokenizers are trained and configured, and how tokenizer choices surface as model bugs

See where you stand

110 questions across four stages: Understand, Apply, Solve and Judge.

Try 5 questions

Practice items, not counted towards your mastery. No account needed.

Check yourself · 1 of 5

In one BPE training step, what exactly gets merged?

Choose one answer

Check yourself · 2 of 5

Why does byte-level BPE have no unknown-token problem?

Choose one answer

Check yourself · 3 of 5

What is the main benefit of a larger BPE vocabulary?

Choose one answer

Check yourself · 4 of 5

What does add_generation_prompt=True do in a Hugging Face chat template?

Choose one answer

Check yourself · 5 of 5

Why can a completion prompt that ends with a trailing space produce odd output?

Choose one answer

Topics

  1. Byte-pair merge algorithm step by step5 min read · Start from bytes, count adjacent pairs, merge the most frequent pair, record the merge and repeat until the target vocabulary size
  2. Byte-level BPE and pre-tokenization rules5 min read · UTF-8 bytes remove unknown tokens, and regex pre-splitting on spaces, digits and punctuation decides which merges can ever happen
  3. Choosing vocabulary size trade-offs5 min read · Larger vocabularies shorten sequences but cost embedding parameters, and multilingual and code coverage push sizes from about 32k to over 200k
  4. Special tokens for roles and boundaries5 min read · Begin, end, padding and role tokens, how chat templates rely on them, and the injection risk when user text can produce them
  5. Tokenizer quirks behind model bugs5 min read · Leading spaces, digit splitting, glitch tokens, trailing whitespace and the extra cost of non-English text that show up as odd model behaviour
  6. Training a tokenizer with real libraries6 min read · Using Hugging Face tokenizers, SentencePiece or tiktoken to train or load a tokenizer, and why swapping a pretrained model's tokenizer needs retraining

Start here

110 questions · last verified 2026-12