liveBook · Manning

Token

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

A discrete unit of text that a language model processes, roughly corresponding to words or punctuation marks in this section.

A token is a discrete unit of text that a language model reads. Depending on the processing scheme, it may represent a word, punctuation mark, subword, or character. Tokens form the bridge between raw text and numerical representations: text is split into tokens, tokens become token IDs, and embedding layers retrieve vectors for model input. section 1.5 section 2.9

A practical token-processing flow is:

  • Split text into words and special characters such as punctuation. section 2.2
  • Use byte pair encoding to represent unfamiliar words as subword units or individual characters. section 2.9
  • Convert tokens into integer token IDs, then use embedding lookup to produce continuous vectors. section 2.9
  • Arrange tokenized data with a sliding window to create input-target pairs for training. section 2.0

Splitting a sentence into tokens

Applying a regular-expression tokenizer to "Hello, world. Is this-- a test?" produces ['Hello', ',', 'world', '.', 'Is', 'this', '--', 'a', 'test', '?']. The result preserves punctuation and separates the double hyphen as its own token. section 2.2

Figure 2.4 A view of the text processing steps in the context of an LLM. Here, we split an input text into individual tokens, which are either words or special characters, such as punctuation characters.
figure

Shows how input text becomes individual word and punctuation tokens before embedding and model processing. section 2.2

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

How deep it goes
Explains word, punctuation, subword, and character units, then connects them to IDs and embeddings without deriving tokenizer internals.
Examples
Demonstrates regular-expression splitting with punctuation, double hyphens, and a 20,479-character short story.
What it assumes
Assumes familiarity with basic language-model and transformer structure while teaching text preparation from raw strings.
What you can do after
Apply Python regular expressions to split text and prepare token sequences for later ID conversion and embedding lookup.
How it connects
Connects tokens to tokenization, byte pair encoding, token IDs, embeddings, positional embeddings, and sliding-window sampling.

Also explained in

Compare how 31 books explain token →

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.