Chapter 5

Subword Tokenization

Rare words, open vocabulary, BPE, merge operations, WordPiece, unigram tokenization, byte-level BPE, special tokens, padding, and truncation.

What this chapter does

Subword tokenization is the practical compromise between characters and words used by many modern language models.

Lessons

Read these in order.

Start with the chapter introduction, then move through the topic lessons. The order is chosen so each page can reuse ideas from the pages before it.

  1. 01
    Introduction

    Subwords as the practical compromise between character and word tokenization.

  2. 02
    Rare Words and Open Vocabulary

    Why fixed word vocabularies cannot cover all names, spellings, code, and new forms.

  3. 03
    Byte Pair Encoding

    Starting from small units and repeatedly merging frequent adjacent pairs.

  4. 04
    Merge Operations

    How an ordered merge list turns characters into larger token pieces.

  5. 05
    WordPiece and Unigram Tokenization

    Related subword-tokenization families and the shared idea behind them.

  6. 06
    Special Tokens, Padding, and Truncation

    The non-text tokens and length decisions that form the model interface.

Before moving on

  • Trace a tiny BPE merge example.
  • Explain why subword tokenization helps LLMs.
  • Recognize tokenizer choices as model-interface choices.

Where this leads

  • Count-Based Language Models
  • Transformers

Chapter progress