liveBook · Manning

Probability theory

As explained in How Large Language Models Work

A probability is a numerical value representing the likelihood assigned to a possible event or outcome.

A probability is a numerical estimate of how likely an event or outcome is. In language-model generation, every vocabulary token receives a probability for being the next token, even when most tokens are nearly impossible. section 3.2.3 section 3.5

The model does not directly output one word. It produces a probability for every possible next token, then sampling randomly chooses among them according to those probabilities. This controlled randomness explains why the same prompt can produce different answers. section 3.2.3 section 3.5

Probability supports several parts of the generation process:

  • Ranks plausible continuations while assigning tiny probabilities to unlikely or nonsensical tokens. section 3.2.3
  • Makes weighted random selection possible, balancing predictable text against more varied output. section 3.2.3 section 3.5
  • Provides reinforcement-learning systems with information about how probable each generated token was, alongside a quality score. section 5.3.1

“I love to eat”

Food tokens such as “barbeque” and “sushi” receive high probabilities, while a car and the number 42 receive low probabilities. Weighted random selection chooses “tacos,” and generation continues until an end-of-sequence token appears. section 3.2.3

Figure 3.11 We demonstrate text generation by starting with the phrase "I love to eat" and then showing that some possible completions that are foods, such as barbeque and sushi, have high proba-bilities, while a car and the number 42 have low probabilities. Weighted random selection chooses the word tacos. The generation loop is stopped when the EoS token appears.
figure

Use the generation figure to follow probabilities from a partial sentence through weighted selection and stopping at the end-of-sequence token. section 3.2.3

How How Large Language Models Work covers it

How deep it goes
Explains token scoring, weighted selection, randomness, and training intuition while deferring deeper mathematical reasons.
Examples
Uses “I love to eat,” food completions, unlikely tokens, weighted selection, and an end-of-sequence token.
What you can do after
Apply it via token sampling to understand and adjust the consistency or variety of generated text.
How it connects
Connects probability with sampling, unembedding, autoregressive models, decoding, attention, and reinforcement learning.

Also explained in

Compare how 16 books explain probability theory →

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.