liveBook · Manning

Tokenization

As explained in Build a Large Language Model (From Scratch)

The process of splitting raw text into tokens for further processing by a language model.

Tokenization splits raw text into words, subwords, and punctuation tokens that an LLM can encode as vectors before transformer processing. It preserves capitalization and may retain or remove whitespace depending on the application. section 2.0 section 2.2

A practical tokenization flow proceeds as follows:

  • Read a text sample and split it initially on whitespace. section 2.2
  • Extend the split pattern to separate punctuation and multi-character symbols such as --. section 2.2
  • Remove redundant whitespace tokens when exact spacing is not required. section 2.2
  • Pass the resulting tokens to token encoding, vector embeddings, and input-output sampling for LLM training. section 2.0 section 2.1

Separating words and punctuation

For `Hello, world. Is this-- a test?`, a regular-expression tokenizer produces `['Hello', ',', 'world', '.', 'Is', 'this', '--', 'a', 'test', '?']`. The same approach can preprocess a larger text sample while retaining capitalization.

How Build a Large Language Model (From Scratch) covers it

How deep it goes
Explains regular-expression tokenization, whitespace choices, and downstream encoding, while deferring detailed byte pair encoding implementation.
Examples
Demonstrates Python regular-expression splits, punctuation cleanup, whitespace filtering, and preprocessing a short story.
What it assumes
Starts with raw text and teaches the transition from words and subwords to tokens and embedding vectors.
What you can do after
Build it from scratch with Python regular expressions and produce cleaned word-and-punctuation token lists for later encoding.
How it connects
Connects tokenization to embeddings, byte pair encoding, transformer architecture, next-word prediction, and data loading.

Also explained in

Compare how 25 books explain tokenization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Large Language Model (From Scratch). The section links point to the parts of the book it draws on.