liveBook · Manning

Tokenization

As explained in Software Testing with Generative AI

Tokenization is the process of converting text into discrete tokens that a language model can process as numeric identifiers.

Tokenization converts natural-language text into smaller, discrete tokens and then maps each token to an integer identifier that a language model can process. section 10.1.1

A prompt becomes token identifiers

The prompt “List me five of the most populated cities in the world.” can be split into tokens that preserve whitespace and punctuation. It then becomes a list of integers, with repeated words receiving the same identifier; the model processes those integers before generating a response. section 10.1.1

Tokenization matters when designing prompts or preparing fine-tuning data:

  • Token boundaries are not fixed to whole words: tokenizers may split larger words or group smaller words. section 10.1.1
  • The tokenizer must align with the model; mismatched token identifiers do not align with the model’s parameters. section 12.2.2
  • Context length limits the number of tokens processed at once, so oversized prompts or training entries may be truncated and lose information. section 12.2.2 section 10.3
  • Tokenization also converts generated model output back into response text. section 10.1.1

How Software Testing with Generative AI covers it

How deep it goes
Explains token splitting, integer mapping, tokenizer alignment, and context-length truncation, but does not detail tokenizer algorithms.
Examples
Uses a city-list prompt, integer token sequences, and fine-tuning examples involving test-code instructions and outputs.
What it assumes
Assumes familiarity with prompts and language models while teaching the machine-readable representation from natural language upward.
What you can do after
Evaluate prompt and training-data limits by estimating token boundaries, checking tokenizer alignment, and identifying context-length truncation risks.
How it connects
Connects tokens with language models, tokenizers, context windows, prompt engineering, retrieval-augmented generation, and fine-tuning.

Also explained in

Compare how 25 books explain tokenization →

Related concepts

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