Skip to main content

Exercises — Entropy: uncertainty over the next token

Self-check questions, exercises, and worked answers

← Back to the lesson: Entropy: uncertainty over the next token

Check your understanding

Extended exercises on this topic.

  1. Does low entropy guarantee that the most likely token is correct?
  2. How does entropy differ from the surprisal of the observed token?
  3. Why must the tokenizer and token-counting convention be specified when comparing perplexity?
Show answers
  1. No. Entropy describes the spread of the distribution, not factual correctness.
  2. Entropy averages surprisal over all possible tokens under the predicted distribution; observed-token surprisal uses the probability assigned to the actual target.
  3. Tokenizers segment text differently, changing the units and positions over which the average is computed.

Calculate token surprisal

For one fixed context, suppose a model assigns the following next-token probabilities:

Candidate token Probability
A 1/2
B 1/4
C 1/8
D 1/8
  1. Calculate the surprisal of each candidate in bits, using \(I(x)=-\log_2 p(x\mid context)\).
  2. Calculate the entropy of this distribution. Why is it an expected surprisal rather than the surprisal of one selected token?
  3. If the observed next token is C, what is its surprisal? Does that value describe the whole distribution?
Show the worked answer
  1. A: 1 bit; B: 2 bits; C: 3 bits; D: 3 bits.
  2. \(H=\frac12(1)+\frac14(2)+\frac18(3)+\frac18(3)=1.75\) bits. It averages the surprisal of all possible outcomes, weighted by their probabilities.
  3. C has 3 bits of surprisal. This is the realized surprisal of that observed event, not the entropy of the distribution.

From token surprisal to a sequence score

Now consider three successive observed tokens. Their conditional probabilities, each evaluated with the observed prefix available at that position, are \(1/2\), \(1/4\), and \(1/8\).

  1. Calculate each token’s surprisal in bits.
  2. Calculate the sequence probability and total surprisal.
  3. Calculate the mean surprisal per token. Is this observed mean automatically equal to the entropy of the model?
  4. At the third step, the observed token has probability \(1/8\). Can you infer the predictive entropy at that step? Compare distributions \((1/2, 1/4, 1/8, 1/8)\) and \((1/4, 1/4, 1/8, 3/8)\) when the third outcome is the target.
Show the worked answer
  1. The token surprisals are 1, 2, and 3 bits.
  2. By the chain rule, the sequence probability is \((1/2)(1/4)(1/8)=1/64\). Its total surprisal is \(-\log_2(1/64)=6\) bits, equal to the sum \(1+2+3\).
  3. The observed mean is \(6/3=2\) bits per token. It is not automatically the model’s entropy: entropy is an expectation under a specified predictive distribution, whereas this mean is calculated from one observed sequence. Dataset-level mean NLL is related to empirical cross-entropy under the chosen targets and token-counting convention.
  4. Both distributions give 3 bits of surprisal for the third outcome. Their entropies differ, with \(1.75\) bits for the first and about \(1.91\) bits for the second. The target score leaves the allocation of probability across the other outcomes undetermined.

Return to the review plan · From hidden states to the predictive distribution · Score observed tokens

Keep the quantities distinct: token surprisal is an event-level value; entropy is an expectation over possible outcomes; sequence log-likelihood sums conditional log-probabilities; mean NLL/cross-entropy adds a target and aggregation convention. See Likelihood for the sequence factorization.

Apply the chain rule to an observed continuation.

Language: Français · English