liveBook · Manning

Tokenization

As explained in Generative AI in Action

Tokenization is the process of converting text into a sequence of discrete tokens for language-model processing.

Tokenization converts prompt or response text into a sequence of discrete tokens that an LLM can process. The model passes these tokens to embedding, then through its encoder-decoder generation pipeline. section 2.8 section 2.8.2

Treat tokens as an operational constraint when designing LLM applications:

  • Control token volume because more tokens increase model processing, cost, latency, and resource requirements. section 2.8.2
  • Expect token boundaries to vary by algorithm: tokens may represent characters, words, sub-words, or larger linguistic units. section 2.8.2
  • Budget for both prompt and response tokens when estimating model limits and throughput. section 2.8.2

A sentence becomes eight tokens

Using an OpenAI tokenizer, “I have a white dog named Champ” is represented as eight tokens. During generation, the model predicts the next token, appends it to the sequence, and uses the expanded context to predict the following token. section 2.8.2

Tokenization also changes search behavior. In a Redis index, a URL stored as a TagField remains one exact-match tag; a TextField tokenizes and indexes its parts for word searches, so each field type must match the intended query. section 8.3

How Generative AI in Action covers it

How deep it goes
Defines tokenization, explains iterative next-token generation, and stops short of algorithm internals.
Examples
Uses an eight-token dog sentence and contrasts Redis TagField exact matching with TextField tokenized searching.
What you can do after
Evaluate token costs and configure Redis fields for exact-match or tokenized search behavior.
How it connects
Ties tokenization to embeddings, encoder-decoder architecture, context windows, completions, and search indexing.

Also explained in

Compare how 25 books explain tokenization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Generative AI in Action. The section links point to the parts of the book it draws on.