0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09How do you grade a paragraph?
In Season One, evaluation was clear: a prediction was right or wrong, or off by a number of minutes. Now Brightcart's assistant writes paragraphs. A customer asks about returns, and there are a hundred good ways to answer: different words, different order, all correct. And one fluent, confident answer that's completely wrong. Evaluating foundation models is one of the hardest problems in AI engineering, and this whole module is devoted to it. We'll start where the models themselves start: the mathematics of predicting text.
Entropy, cross-entropy and perplexity, what they tell you, and, just as important, what they don't. Season Four, Module Fifteen: evaluation methods. First stop: entropy, cross-entropy and perplexity.
1:05Why evaluating AI is so hard
Why is evaluating these models so hard? Many different answers can be equally good, so there's often no single correct reference. Quality has many dimensions: correct, helpful, safe, concise, in the right tone. We often can't see a model's training data or internals, especially with API models. Public benchmarks get saturated quickly, or leak into training data. And as we trust models with more, the cost of an undetected failure rises. Over this module and the next, we'll build a complete toolbox. We begin with the metrics that come built into language modelling.
1:45Information, surprise and entropy
Let's start with surprise. If something is very likely and it happens, you learn little. If something rare happens, you learn a lot. Information theory measures surprise as minus the log of the probability. Measured in log base two, the unit is the bit. Entropy is the average surprise of a source. A fair coin has an entropy of exactly one bit: one yes-or-no question settles each flip. A coin that lands heads ninety percent of the time is more predictable: about zero point four seven bits. A fair four-sided die: two bits.
You've met entropy before, choosing decision-tree splits in episode fourteen. Here, it measures how unpredictable text is.
2:34Cross-entropy: how well a model predicts
Entropy describes the text itself. To evaluate a model, we ask how surprised the model is by the real text. That's cross-entropy. Think of it as betting. Before each token, the model spreads its bets across all possible next tokens. When the real token arrives, the model's penalty is minus the log of the probability it bet on that token. Here are four real tokens, which the model gave probabilities of a half, a quarter, eighty percent and ten percent. The penalties are zero point six nine, one point three nine, zero point two two and two point three.
The average is one point one five, in natural-log units called nats, or about one point six six bits per token. This is exactly the loss that models minimise during pre-training. And it can never be lower than the true entropy of the text. The gap between them is how much better the model could, in principle, still get.
3:37Perplexity: the effective number of choices
Cross-entropy is a slightly abstract number, so we often convert it to perplexity, by raising e to its power. Perplexity has a lovely meaning: the effective number of choices the model is torn between at each step. A model guessing uniformly among four options has a perplexity of exactly four. Our example has a perplexity of about three point one six, as uncertain as if it were choosing among roughly three equally likely tokens each time. Lower is better. Remember our tiny GPT from episode forty-three? Its final validation loss of zero point one seven nine per character is a perplexity of about one point two: on its very repetitive Brightcart corpus, it was rarely torn between more than one or two characters.
4:29Bits per character, and comparing fairly
Here's a trap. Perplexity is measured per token, and different models split text into tokens differently. A model with a bigger vocabulary uses fewer, longer tokens, so its per-token numbers aren't directly comparable with a model that uses more, shorter tokens. The fix is to normalise by characters or bytes. Bits per character: divide the bits per token by the average number of characters per token. If our example tokens average four characters, one point six six bits per token becomes about zero point four two bits per character.
Our tiny GPT, which already worked in characters, comes out at about zero point two six. There's a beautiful connection here: predicting text well and compressing it well are the same thing. A model that needs fewer bits per character could, in principle, store text in fewer bits.
5:26What these metrics are good for
These metrics are genuinely useful. They let you compare models fairly when you normalise properly, and track training progress. They help filter data: text with very high perplexity is often gibberish, and text with surprisingly low perplexity is often repeated boilerplate. They can reveal contamination: if a model finds a benchmark's test questions suspiciously easy to predict, it may have seen them during training. And a model's perplexity on Brightcart's own support conversations hints at how familiar it is with this kind of text.
6:04What perplexity can't tell you
But perplexity has clear limits. It measures how well a model predicts text, not whether its answers are correct, helpful or safe. A fluent, confident answer that invents a return policy can have lower perplexity than an awkward but correct one. There's a twist too. After post-training, assistant models are tuned to be helpful rather than to mimic all text, so their perplexity on ordinary text often gets worse than the base model's, even though they're far more useful. And many API models don't even reveal their token probabilities.
So for an application like Brightcart's assistant, we need to evaluate the answers themselves. That's next.
6:48Try it yourself: entropy of three outcomes
After "Your parcel will arrive", suppose the next word is "tomorrow" half the time, and "today" or "soon" a quarter of the time each. What's the entropy, in bits? Pause. "Tomorrow" carries one bit of surprise, and each of the others carries two. Weight them by how often they happen: half times one, plus a quarter times two, plus a quarter times two: one and a half bits. That's more uncertain than a fair coin, at one bit, but less than a fair four-sided die, at two.
7:30Surprise, in bits
Here's a feel for surprise in bits. Something with a probability of a half carries one bit. One in eight: three bits, because you halve the probability three times. One in a hundred: about six point six bits. And a blind guess over a fifty-thousand-token vocabulary carries about fifteen point six bits per token. Every time the probability halves, the surprise goes up by exactly one bit. Language models are trained to drive that average surprise down.
8:03Try it yourself: the cost of a wrong belief
Suppose the truth is fifty-fifty between "tomorrow" and "today", but the model believes ninety-ten. What's its cross-entropy? Pause. The truth's own entropy is one bit; that uncertainty can't be avoided. But the model's cross-entropy is about one point seven four bits. The extra zero point seven four bits is the KL divergence: the cost of believing the wrong distribution. That's why cross-entropy can never go below the data's true entropy, and why the gap between them is exactly what training tries to close.
8:45Pause & Predict: which model is really better?
Model A has a perplexity of twelve; model B, nine. B looks better. But A's tokeniser averages four characters per token, and B's only three. Which is really better at predicting the text? Pause. Convert both to bits per character. A: the log base two of twelve, about three point six bits per token, divided by four characters: about zero point nine. B: about three point two bits per token, divided by three: about one point zero six. Model A is actually better. B's smaller tokens made each prediction easier, without making it better at the text overall.
Only compare perplexities between models that share a tokeniser.
9:37Catching contamination with perplexity
Perplexity can work as a detective. Take a public benchmark, and write fresh questions of the same style and difficulty. If a model finds the benchmark text far less surprising than the fresh questions, that's suspicious: it may have seen the benchmark during training. It isn't proof, but it's a reason to dig deeper, for example by testing the model on newly written questions it can't possibly have memorised.
10:05Watching for drift
Brightcart can also use perplexity to watch for change. Each week, score incoming customer messages with a fixed reference model, and plot the average perplexity. One week, it jumps. The team investigates and finds the cause: a new range of smart kettles has brought new words and new kinds of questions. That's drift, and it's a signal to add those questions to the evaluation set and check that the assistant handles them well.
10:37Pause & Predict: is lower perplexity always better?
If model A has lower perplexity than model B, is A the better assistant? Pause. Not necessarily. Post-training often makes a model slightly worse at predicting raw web text, but much better at helping people. Perplexity measures how well a model predicts text, not whether it follows instructions, tells the truth about a specific order, stays safe, or uses the right tone. It's a superb tool for comparing base models and spotting data problems, and a poor judge of an assistant on its own.
11:15Uncertainty from the model's own probabilities
A model's own probabilities can hint at uncertainty. When it writes "your refund will arrive in", is the next token a sharp, confident choice, or spread across three, five, seven and ten days? A flat, high-entropy distribution at a key fact is a useful warning sign: flag the reply, or fetch the real data first. But remember the limitation: models can be confidently wrong, so low entropy never guarantees a correct answer.
11:46One number, three costumes
Cross-entropy wears different costumes, and it helps to recognise them. Training code usually reports it in nats, using the natural logarithm: our example was one point one five one nats per token. Divide by the natural log of two, and it becomes one point six six one bits. And perplexity comes out the same either way: e to the one point one five one, or two to the one point six six one, both about three point one six. Same number, different units, so always check which one a report is using.
12:24How predictable is English?
How predictable is English, really? In nineteen fifty-one, the information theorist Claude Shannon asked people to guess the next letter of passages, one letter at a time. From their guesses, he estimated that English carries roughly one bit of information per character, far below the four point seven bits you'd need if every letter were equally likely. Language is highly predictable, and that predictability is exactly what language models learn to exploit.
12:56Myth vs Fact
Myth: the model with the lowest perplexity makes the best assistant. Fact: perplexity measures how well a model predicts text, and it depends on the tokeniser and the test text. It's excellent for training, data work and contamination checks, and the wrong tool for choosing an assistant.
13:16Recap
Let's recap. Evaluating foundation models is hard because their outputs are open-ended and multi-dimensional. Information theory measures surprise as minus the log of a probability, and entropy as the average surprise. Cross-entropy measures how surprised a model is by real text, and perplexity converts that into the effective number of choices. Normalise by characters when comparing different tokenisers. These metrics are great for training, data quality and contamination checks, but they don't tell you whether answers are right.
One sentence to remember: perplexity measures surprise, not truth.
13:57Next: exact evaluation
Mission complete. Brightcart now knows how to use perplexity wisely: for comparing models on its own text, cleaning data, and checking for contamination. Next, we score the answers themselves. When there's a right answer, how do we check it automatically? From running code against tests, to exact matches, to measuring how similar two answers are in words, and in meaning. Exact evaluation, next. See you on the map.