liveBook · Manning

Token probability

As explained in Build a Reasoning Model (From Scratch)

The probability assigned by the model to a candidate token at a particular position in the output sequence.

Token probability is the normalized probability a language model assigns to each possible next token at a particular position. The model distributes probability mass across its vocabulary after converting logits with softmax; reading the probability of each observed next token measures how compatible a proposed sequence is with the model's preferences. section 5.4

Compute token probabilities for a proposed sequence as follows:

  • Multiply the conditional probabilities to estimate the sequence's joint probability; very small products can make direct comparison numerically inconvenient. section 5.5

Berlin versus Bridge

For "The capital of Germany is Berlin," the displayed next-token probabilities produce a joint probability of 5.9372e-08. Replacing Berlin with Bridge lowers the final token probability to 2.9802e-07 and the joint probability to 1.0481e-13, indicating much weaker model support.

Token probabilities support response scoring: consistently high values suggest model compatibility, while many low values suggest weak support. They can rank candidate responses, break ties in self-consistency, and provide a signal for iterative self-refinement. section 5.4 section 5.1

How Build a Reasoning Model (From Scratch) covers it

How deep it goes
Explains logits, softmax, indexed next-token extraction, and joint multiplication, then defers numerical stability to log probability.
Examples
Demonstrates PyTorch scoring with Germany-capital prompts ending in Berlin or Bridge and compares per-token and joint probabilities.
What it assumes
Assumes token IDs, model logits, and next-token generation, while grounding probability computation in those mechanisms.
What you can do after
Build it from scratch with PyTorch by extracting per-token probabilities and multiplying them into a sequence score.
How it connects
Connects token probability to logits, softmax, sequence likelihood, log probability, self-consistency, self-refinement, and reinforcement learning.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Reasoning Model (From Scratch). The section links point to the parts of the book it draws on.