KatInterview

Self-Information, Log Bases, and Perplexity in Language Models

Machine LearningModel answer
MediumModel answerMachine Learninginformation-theorylanguage-modelingcross-entropy

Last updated

Define the information content of a token, explain how the log base sets its unit, link it to cross-entropy and perplexity, and spot common mistakes when reading or comparing these numbers.

You are reviewing the evaluation of a language model with a colleague, and the conversation turns to surprisal, the information content of a predicted token. Answer the following.

  1. Definition. Give the formula for the surprisal of an event with probability (p). Explain why the logarithm is the natural choice, and say what surprisal means for a token inside a language model.
  2. Units. Surprisal comes in different units, much as length comes in meters or feet. What decides which unit you get? List the common units and show how to convert between them.
  3. Connections. How does surprisal relate to entropy, cross-entropy, the training loss, and perplexity? Include a short numeric example that moves between nats, bits and perplexity.
  4. Pitfalls. Which mistakes commonly occur when people compute, average, compare or interpret surprisal and perplexity values?

Aim for an answer that is short and exact, and include at least one worked number.

Hints

Hint 1

Start from the requirement that independent events should have additive information, and see what function of probability that forces.

Hint 2

The unit is purely a matter of which logarithm base you use. Work out how 1/8 looks in base 2 versus base e, then find the factor that converts between them.

Hint 3

Per-token average surprisal on a corpus estimates cross-entropy, and perplexity is that average exponentiated in the same base. Then think about what changes if two models split the same text into different numbers of tokens.

Hint 4

For pitfalls, consider base mismatches, tokenizer differences, how you average across sentences, subword versus word-level scores, padding/BOS/EOS handling, and zero probabilities.