Rendered Source Note

Hugging Face — Summary of the Tokenizers (BPE, WordPiece, Unigram)

Generated HTML view. Markdown remains canonical.

Hugging Face — Summary of the Tokenizers (BPE, WordPiece, Unigram)

Type: official-doc Tier: 1 (Official Doc) Author(s): Hugging Face (Transformers documentation) Date: Accessed 2026-06-01 URL: https://huggingface.co/docs/transformers/en/tokenizer_summary Accessed: 2026-06-01

Why This Source Matters

This is the authoritative, worked-example explanation of how subword tokenization algorithms actually build their vocabularies. Where tiktoken-bpe.md gives the API, this source gives the mechanism: it walks BPE merge-by-merge on a tiny corpus, so the learner can reproduce the algorithm by hand. It also establishes the word-vs-character-vs-subword tradeoff that motivates tokenization in the first place — the conceptual spine of Project 02's tokenization half.

Key Claims

The motivating tradeoff (why subword)

Byte Pair Encoding (BPE), step by step

  1. A pre-tokenizer splits text into words + frequencies, e.g. ("hug",10), ("pug",5), ("pun",12), ("bun",4), ("hugs",5).
  2. Build a base vocabulary from all characters: ["b","g","h","n","p","s","u"].
  3. Iteratively merge the most frequent adjacent pair. "u"+"g" is most frequent → merge into "ug", add to vocab.
  4. Next most frequent pair "u"+"n" → merge into "un".
  5. Continue until the target vocabulary size is reached. Final vocab size = base size + number of merges. Example: original GPT uses BPE with vocab 40,478 = 478 base + 40,000 merges.

Byte-level BPE (what GPT-2 / tiktoken use)

Contrast algorithms (for accurate mental model)

Relevant To

Notes