liveBook · Manning

Decode

As explained in How Large Language Models Work

Decoding is the process of converting a model’s internal representation or token distribution into output tokens or text.

Decoding turns the transformer’s numeric representation into readable output tokens. An LLM does this one token at a time, using each selected token to help choose the next. section 3.2.3

A simplified decoding loop works like this:

  • Calculate a probability for every possible next token. section 3.2.3
  • Select a token according to those probabilities, then add it to the output. section 3.2.3
  • Repeat until the model produces an end-of-sequence token or reaches a maximum generation limit. section 3.2.3

Choosing a completion

Given “I love to eat,” food-related completions such as barbecue and sushi receive higher probabilities than a car or 42. Weighted random selection might choose “tacos,” after which decoding continues.

Decoding can also enforce constraints while output is being generated. A format checker can detect an invalid token, such as a newline where a semicolon is required, and regenerate or stop the output. section 5.4.3

How How Large Language Models Work covers it

How deep it goes
Explains unembedding, probability-based sampling, autoregressive repetition, stopping conditions, and format checks without deriving the underlying mathematics.
Examples
Uses “I love to eat” completions and invalid Python formatting to illustrate selection and constrained generation.
What it assumes
Assumes familiarity with tokens, vocabularies, transformer outputs, and probability-based selection.
What you can do after
Evaluate how LLMs generate text token by token and apply format checks or regeneration during output.
How it connects
Connects decoding with unembedding layers, sampling, autoregressive generation, vocabulary, and end-of-sequence tokens.

Also explained in

Compare how 15 books explain decode →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of How Large Language Models Work. The section links point to the parts of the book it draws on.