All courses

Evaluating LLMs: loss, logprob scoring, benchmarks

Score a multiple-choice question either by comparing answer log-probabilities or by generating an answer. Explain what benchmarks like MMLU measure and their pitfalls: contamination, prompt format and saturation.

Builds on: Loss per token and perplexity, Deduplication, memorization and contamination

▶ Watch this lesson Start the whole course

What the animation says

Loss isn't a grade

Held-out loss tells you how well a model predicts text. It doesn't tell you whether it can answer a chemistry question. And loss can't even be compared across tokenizers. So we use a benchmark: a fixed set of questions with an answer key, scored as accuracy. But the model never says 'B'. It only gives probabilities for the next token. Turning those into 'answered B, correct' is the whole trick.

Two ways to extract an answer

Way one: logprob scoring. Feed the question, then each candidate answer, and ask how probable the model finds that answer's tokens. Pick the most probable. Nothing is generated, so the format can never be wrong. Score the full answer text, or list lettered options and score just the letter after 'Answer'. Way two: generation. The model writes a reply, a pattern pulls out the answer, and it's compared to the key. Here the model replies: 'Probably the second one.' The pattern finds no letter. How is this graded?

The logprob score

Counted wrong. Logprob scoring avoids that problem. Here's its score. For each answer token, take its log probability given the question and earlier answer tokens. Add them up. Each term is zero or below, so every extra token can only lower the sum. What purrs? Answer A, 'dog': one token, minus two. Answer B, 'a house cat': three tokens, minus one point two, minus zero point nine, minus zero point three. With the sum, which answer wins?

Sum vs mean

The sum picks 'dog': minus two beats minus two point four. Wrong, and only because B has more tokens. The fix: length-normalize. Divide each sum by the answer's token count. Dividing by characters instead also takes the tokenizer out of the picture. Here are both divisions. Tap the answer the mean picks.

The method is part of the score

The mean picks the cat: minus zero point eight against minus two. But normalizing can also err, by favouring a long wrong answer. Letter scoring is a third way: list both options and compare the probability of 'A' versus 'B' after 'Answer'. Three valid methods, possibly three different picks. So a score only means something together with its method.

Reading an MMLU score

MMLU: about fourteen thousand four-option questions in fifty-seven subjects, from school to professional level. Chance is twenty-five percent. Contamination: the questions are public, so a model may have trained on them. Prompt format: wording, the number of solved examples, and letter versus text scoring have moved one model by over ten points. Saturation: top models pass ninety percent, and a few percent of keys are wrong, so the last gaps mean little. Two models, two setups. Tap why this gap may say nothing.

How do you grade a next-token predictor?

Held-out loss tells you how well a model predicts text. It does not tell you whether the model can answer a chemistry question. Per-token loss and perplexity are also not comparable across tokenizers. A **benchmark** is a fixed question set with an answer key, scored as accuracy. But the model only outputs next-token probabilities. How do you turn those into "answered B, correct"? And when can you trust the final number?

Two ways to extract an answer

**Logprob scoring:** feed the question, then each candidate answer. Ask how probable the model finds that answer's tokens, and pick the most probable one. Nothing is generated, so the model can never answer in the wrong format. You can score the full answer text. Or you can list the options with letters in the prompt and score just the letter token after "Answer:". **Generation:** let the model write a reply, pull out the answer with a pattern, and compare it to the key. This is closer to real use, but an unparseable reply counts as wrong.

The logprob score of an answer

$$s(a)=\sum_{i=1}^{n_a}\log p_\theta(a_i\mid q,\,a_{<i})$$ $q$: question tokens. $a_i$: the $i$-th token of candidate answer $a$. $n_a$: its token count. Predict the answer with the highest score, $\arg\max_a s(a)$. Every term is $\le 0$, so each extra token can only lower the sum, and longer answers are penalized. The length-normalized score $\bar s(a)=s(a)/n_a$ fixes this. Dividing by characters instead also avoids tokenizer dependence. Accuracy is the fraction of questions answered correctly; chance is $1/\#\text{options}$.

Sum vs mean flips the answer

Question: "What purrs?" - A: "dog" is 1 token with log p $=-2.0$. Sum $-2.0$, mean $-2.0$. - B: "a house cat" is 3 tokens with log p $-1.2,-0.9,-0.3$. Sum $-2.4$, mean $-0.8$. The sum picks the wrong A ($-2.0>-2.4$), only because B has more tokens. The mean picks B ($-0.8>-2.0$). Normalizing can also err the other way, by favoring a long wrong answer. Letter scoring instead compares $p(\text{"A"})$ with $p(\text{"B"})$ after "Answer:". Different valid methods can pick different answers, so a score is only meaningful together with its method.

Reading an MMLU score

**MMLU** has about 14,000 four-option questions in 57 subjects, from school to professional level. It mainly measures broad knowledge. Chance is 25%. - **Contamination:** the questions are public on the web, so a model may have trained on them. - **Prompt format:** wording, the number of solved examples in the prompt, and letter vs text scoring have moved one model's score by over 10 points. - **Saturation:** top models exceed 90%, and a few percent of the keys are wrong, so the remaining gaps stop meaning much.

What to remember

Score a multiple-choice question either by comparing answer log-probabilities (summed or length-normalized) or by generating a reply and parsing the answer. The method changes the number. A benchmark score is comparable only under identical prompts and scoring. Contamination inflates it, and saturation makes it stop separating strong models.

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.