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














