Chapter 4

Tokens and Vocabularies

Tokens, vocabularies, unknown tokens, character tokens, word tokens, subword motivation, rare words, and vocabulary size tradeoffs.

What this chapter does

Tokenization is a modeling decision. This chapter compares character and word views before subwords enter.

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

    Tokens as the interface between raw text and language-model computation.

  2. 02
    What Is a Token?

    A token as the unit the model reads, predicts, and stores in a vocabulary.

  3. 03
    Vocabularies and Unknowns

    How a finite token list creates ids, counts, and unknown-token behavior.

  4. 04
    Character Tokens

    A small-vocabulary view that makes spelling visible but stretches sequences.

  5. 05
    Word Tokens

    A short-sequence view that makes words visible but struggles with rare and new forms.

  6. 06
    Rare Words and Vocabulary Size

    The tradeoff between vocabulary size, sequence length, memory, and open vocabulary.

Before moving on

  • Explain why neither characters nor words solve everything.
  • Compare sequence length and vocabulary size.
  • Understand why subwords are needed.

Where this leads

  • Subword Tokenization
  • Count-Based Language Models

Chapter progress