liveBook · Manning

Entropy

As explained in Build a Reasoning Model (From Scratch)

A measure of uncertainty in the model's output distribution during generation, where low entropy indicates collapse and high entropy indicates randomness.

Entropy measures uncertainty in the next-token distribution during generation. High entropy spreads probability across many tokens and supports exploration; low entropy concentrates probability on one token, producing deterministic behavior and potentially signaling training collapse. section 7.3.2

Interpret entropy values as a training diagnostic:

  • Very low entropy, approximately 0–0.5, indicates that one token dominates. section 7.3.2
  • Moderate entropy, approximately 1–2, indicates probabilities shared across a reasonably small token set during stable training. section 7.3.2
  • High entropy approaches the logarithm of the vocabulary size and indicates broad uncertainty. section 7.3.2

Computing token and sequence entropy

Convert logits with torch.softmax() and torch.log_softmax(), then calculate entropy as the negative sum of probability–log-probability products. For generated answers, average per-step entropy after the prompt and compare it with the sequence log-probability. section 7.3.2

Figure 7.7 Log probability (logprob) computation of a single token ("this") in the LLM’s generated answer. The LLM returns the logits of the token, which are then converted to softmax probability values via torch.softmax() or logprob values via torch.log_softmax().

Trace how logits become probabilities and log-probabilities before forming the entropy metric. section 7.3.2

How Build a Reasoning Model (From Scratch) covers it

How deep it goes
Explains token-level and sequence-average calculations with PyTorch operations, stopping short of broader training analysis.
Examples
Uses seven-token example logits, selected-token log-probabilities, and averaged answer-step entropy.
What it assumes
Builds from logits, softmax probabilities, and log-probabilities, while revisiting log-probability calculation.
What you can do after
Apply it via PyTorch to compute token and answer-sequence entropy during model training or generation.
How it connects
Connects entropy to logits, softmax, log-probability, token probabilities, exploration, and reinforcement learning.

Also explained in

Compare how 13 books explain entropy →

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.