Evaluation metrics

What each score rewards, what it cannot see, and how much to trust it: classification at a threshold, ROC and precision-recall, calibration, multi-class averages, regression and ranking metrics, text overlap, perplexity, and error bars. Computed live on real model outputs (SST-2 classifiers, a diabetes regression, three small language models, roberta-large embeddings), every engine checked against scikit-learn, sacrebleu, rouge-score, NLTK and bert-score. A child page of Topic: ml-fundamentals. Data as of October 2026. Reading: 27 min, plus 7 in closed details.

The idea in one screen

A metric is a decision about which errors count and how much: most classification scores are ratios of one confusion matrix at one threshold, the rest summarise every threshold (ROC-AUC, average precision) or the probabilities themselves (log-loss, Brier, ECE), and each one is blind to whatever its choice leaves out.

Two more ideas carry the page. An average hides whom it averages over: examples (accuracy, micro), classes (macro), tokens (perplexity), queries (MRR), n-gram orders (BLEU). Every number from a finite test set has an error bar, and on a few hundred examples it is often wider than the gap being reported.

Predict, then drag. Switch to "Rare positives" and the threshold sits at 0.5. Press "Best MCC" (0.79), then drag back to 0.5: the same 97 extra false alarms appear. Which dot moves further, the one on the ROC curve or the one on the precision-recall curve?

Confusion matrix
the four counts at one threshold: true and false positives (TP, FP), true and false negatives (TN, FN)
Prevalence
the share of positives in the data; what ROC ignores and precision feels
Proper scoring rule
a score of probabilities whose expected value is best when the forecast equals the true probability
Calibration, ECE
whether "0.8" means 80% of the time; expected calibration error is the binned gap
Macro, micro, weighted
averaging over classes equally, over pooled examples, or by class size
nDCG, MRR
ranking scores for one ordered list per query, rewarding relevant items near the top
Bits per byte
a model's loss per byte of text, comparable across tokenizers, unlike per-token perplexity
Every metric in one table: what it rewards and cannot see (reference)
MetricRewardsCannot seeReach for it when
AccuracyRight decisions, all counted alikeWhich class the errors fall in; a rare classClasses are balanced and errors cost the same
Precision, recall, FβCatching positives (recall) without false alarms (precision)True negatives entirely; the threshold you did not pickOne class is the one you act on
MCCAll four cells of the confusion matrix at onceProbabilities; costs that differ by cellOne number for an imbalanced binary task
ROC-AUCRanking positives above negativesPrevalence, hence false alarms per real positiveClasses are not too skewed, or you compare rankers
AUPRC, average precisionRanking with precision kept highNegatives ranked below every positivePositives are rare and false alarms cost
Log-loss, Brier, ECEProbabilities that mean what they sayNothing about ranking that a tie cannot hideDownstream code uses the probability
Macro, micro, weightedClasses equally, examples equally, or by sizeRespectively: class size, small classes, small classesEvery multi-class report: say which
MAE, RMSE, R², MAPESmall errors: typical (MAE), with large ones punished (RMSE), against predicting the mean (R²), relative (MAPE)Respectively: rare large misses, the typical case, the scale, small true valuesRegression: say which, with the units
Recall@k, MRR, nDCGRelevant items in the top k, the first one early, graded items near the topOrder inside k; everything after the first hit; anything never judgedSearch, retrieval, recommendation
BLEU, ROUGE, chrF, METEORSurface overlap with a referenceMeaning: a negation scores almost perfectTranslation or summary regression tests with references
BERTScore, MoverScoreOverlap of contextual embeddingsNegation, still; numbers and factsParaphrase-heavy outputs, as one signal among several
PerplexityProbability the model gives held-out textGeneration quality; comparability across tokenizersComparing models that share a tokenizer and text

Rows are this page's summaries of the sections below, where each claim is sourced and, where it is a number, computed.

One threshold turns 872 real scores into four counts, one point on each curve

Model
Data
Scores by true class; the threshold is the line
Confusion matrix (click a cell to read its sentences below)
ROC: recall against false positive rate
Precision against recall (dashed: chance = share of positives)
Sentences in the selected cell (the real SST-2 sentences behind the counts)

    Answer: on rare positives the ROC dot moves right by 0.23 (FPR 0.019 to 0.245, because FPR divides by all 428 negatives) while the precision dot falls by 0.52 (0.771 to 0.250, because precision divides by the model's own 35 to 140 positive calls). Models: TF-IDF word and bigram features with logistic regression (C = 1); word and bigram counts with multinomial naive Bayes (alpha 1); the same naive Bayes with 5-fold isotonic calibration; all trained on the 67,349 SST-2 training phrases and scored on the 872 validation sentences (stanfordnlp/sst2, Socher et al. 2013; positive sentiment is the positive class). "Rare positives" keeps every tenth positive sentence in file order (45 of 444) and all 428 negatives. Every metric checked against scikit-learn at threshold 0.5 by src/check_core.mjs. Sentences are cut to 90 characters.

    1 · Classification at a threshold

    Every metric here is a ratio of the four counts in the hero's matrix at one threshold (Google ML Crash Course). F1 never looks at TN: it scores the class you act on, which suits search or fraud alerts but means F1 changes if you swap which class is called positive. MCC is symmetric in the two classes and is high only when all four cells are good, which is why Chicco and Jurman (2020) argue for it over F1 and accuracy on imbalanced binary tasks.

    Fig. 1, step by step

    1. 872 real scores, two rows. Each column is a 0.025-wide bin of the logistic regression's probability of "positive" on the SST-2 validation sentences, as tall as the sentences in it: the front row holds the 444 positive reviews, the back row the 428 negative ones. The rows overlap in the middle, so no threshold separates them.
    2. A threshold at 0.5 cuts four counts. The glass plane predicts positive to its right. Columns turn green where the call is right and purple where it is wrong, and flow into the four stacks of the confusion matrix: TP 379, FP 105, FN 65, TN 323. Accuracy 80.5%, precision 0.783, recall 0.854.
    3. Raise it, and the errors trade places. At 0.79 false positives fall to 8 and precision rises to 0.969, but false negatives grow to 195 and recall falls to 0.561. Every threshold metric is a ratio of the same four stacks at one threshold.
    4. Make positives rare. Keep every tenth positive (45 of 444) and all 428 negatives: the front row shrinks tenfold, the back row stays. Back at 0.5, the 105 false positives now outnumber the 35 true positives: precision 0.250, accuracy 75.7%, MCC 0.34.
    5. Always negative. Slide the plane past every score: nothing is called positive, the TP and FP stacks empty, and accuracy is 90.5%, higher than the classifier's, with recall 0 and MCC 0.
    6. The best threshold on this data. At 0.79 the model makes 36 positive calls, 28 of them right: accuracy 94.7%, MCC 0.67. It was chosen on the very data it is scored on, which flatters it: the trap below.
    The formulas (accuracy, precision, recall, F1, Fβ, FPR, specificity, balanced accuracy, MCC)
    MetricFormulaReads as
    Accuracy(TP + TN) / allShare of decisions that were right
    PrecisionTP / (TP + FP)Of everything I flagged positive, how much was right
    Recall (true positive rate, sensitivity)TP / (TP + FN)Of all actual positives, how many I caught
    F12PR / (P + R)Harmonic mean of precision and recall
    Fβ(1 + β²)PR / (β²P + R)Recall counted β times as important as precision (van Rijsbergen 1979, chapter 7)
    False positive rate (FPR)FP / (FP + TN)Fraction of actual negatives wrongly flagged
    Specificity (true negative rate)TN / (TN + FP)1 − FPR
    Balanced accuracy(recall + specificity) / 2Accuracy with both classes weighted equally
    MCC(TP·TN − FP·FN) / √((TP+FP)(TP+FN)(TN+FP)(TN+FN))Correlation between decision and truth, from −1 to 1, 0 for guessing (Matthews 1975)

    The accuracy trap, on the hero's data. On all 872 sentences (444 positive, 428 negative) accuracy is a fair summary. Keep every tenth positive and the same logistic regression faces 45 positives among 473 sentences:

    Computed live from the shipped scores (src/data_sst2.py, checked against scikit-learn by src/check_core.mjs). The best-MCC row picks the threshold on the same data, so it flatters the model; choose a threshold on held-out validation data, or report a threshold-free metric.

    Saying nothing beats the real classifier at the default threshold, although only the classifier finds any positives; moving the threshold lifts accuracy and doubles MCC. On imbalanced data the default 0.5 is rarely right, and accuracy alone cannot tell a useful model from a silent one: report MCC or per-class precision and recall, with the base rate. What to do about imbalance in training (re-weighting, re-sampling, focal loss) is in Topic: ml-fundamentals, tab "When training goes wrong".

    2 · Every threshold at once: ROC and precision-recall

    Sweeping the threshold traces the hero's two curves. ROC-AUC, the area under recall against FPR, equals the probability that a randomly chosen positive is scored above a randomly chosen negative, ties counted half (Hanley and McNeil 1982; Fawcett 2006). The area under precision against recall is AUPRC. A random ranker scores ROC-AUC 0.5 whatever the classes but AUPRC equal to the share of positives, so the two areas are not on the same scale.

    Why ROC misleads when positives are rare is one denominator. FPR divides by all negatives, a huge number, so thousands of extra false positives barely move it; precision divides by the model's own positive calls and is hit by every one (Davis and Goadrich 2006). Use AUPRC, or precision at the recall you need, when positives are rare.

    Two more results from Davis and Goadrich. One curve dominates another in ROC space if and only if it dominates in PR space. But PR points cannot be joined by straight lines, because precision does not interpolate linearly, so a trapezoidal PR area is optimistic. scikit-learn's average_precision_score therefore sums precision times each step in recall with no interpolation; "AUPRC" in papers may be either, and the two differ, so say which you computed.

    Same classifier, positives made rare: ROC barely moves, precision-recall falls

    ROC
    Precision against recall

    The SST-2 logistic regression on all 872 sentences (51% positive) and on the rare-positive subset (10%): ROC-AUC and , average precision and .

    Same 872 predictions before and after isotonic calibration

    positive reviewnegative reviewobserved rate in binperfect calibration

    Answer: log-loss halves (0.85 to 0.45) while accuracy moves half a point and ROC-AUC barely moves; ECE falls from 0.135 to 0.076. Real predictions: multinomial naive Bayes (alpha 1, word and bigram counts) and the same model with 5-fold isotonic calibration (CalibratedClassifierCV), both trained on SST-2 train; logistic regression as in the hero for reference. Log-loss clips probabilities at 10−15, the default of older scikit-learn versions; with a 10−6 clip naive Bayes scores 0.83 instead of 0.85.

    3 · Probabilities: calibration, log-loss and Brier

    A classifier is calibrated when, of all the examples it gives probability 0.8, about 80% are positive. Ranking metrics cannot see this. Log-loss is −mean log p(true class), the training loss read as a measurement; the Brier score is the mean squared error of the probability against the 0 or 1 outcome (Brier 1950). Both are proper scoring rules, so neither can be gamed by hedging (Gneiting and Raftery 2007). A reliability diagram bins predictions by confidence and plots the observed rate per bin; the expected calibration error (ECE) is the sample-weighted mean gap over the bins (Guo et al. 2017, who found modern deep networks, unlike those of a decade earlier, poorly calibrated, and that temperature scaling, one parameter, fixes most of it). ECE depends on the binning (here 10 equal-width bins) and is not a proper scoring rule. The same diagram for language models' next-token probabilities, measured on GPT-2 and Qwen2.5-0.5B with temperature scaling, is on Probability for ML, section 8.

    The more accurate model is the worse forecaster. Naive Bayes on the same features is slightly more accurate than logistic regression ( against at 0.5) and ranks almost as well, yet multiplies word evidence as if words were independent, which pushes its outputs towards 0 and 1 (Niculescu-Mizil and Caruana 2005). Isotonic regression, a monotone step function fitted on cross-validated predictions (Zadrozny and Elkan 2002), maps them back towards observed frequencies without changing their order.

    Predict, then watch: between the first and the last naive Bayes step, which of accuracy, ROC-AUC and log-loss moves most?

    1. Naive Bayes, as trained. Each dot is one of the 872 validation sentences, placed at the probability of "positive" the model gives it; blue dots are positive reviews, orange negative. Most dots sit at the two edges: the model is almost always nearly certain.
    2. Bin by confidence. Cut the probability axis into 10 equal bins. Below, each bin's green bar is the share of its sentences that really are positive; a calibrated model's bars would reach the diagonal.
    3. The gaps are the calibration error. Sentences given about 0.98 are positive far less often than 98% of the time, and those given 0.02 far more often than 2%. ECE is the gap per bin (red) weighted by the bin's share of sentences.
    4. Isotonic calibration moves every dot. A monotone step function, fitted on cross-validated training predictions, maps each probability to the observed frequency for scores like it. Order is kept, so the ranking (ROC-AUC) barely moves; the dots leave the edges.
    5. Re-binned: much closer, not perfect. ECE falls from 0.135 to 0.076, log-loss from 0.85 to 0.45, the Brier score from 0.157 to 0.142; accuracy moves by half a point because a few sentences cross 0.5. The top bins are still overconfident: the map was fitted on training phrases, many of them short fragments, and these are full sentences, so calibration learned on one distribution only partly transfers to another.
    6. For reference: logistic regression. Trained by minimising log-loss, logistic regression is close to calibrated without any correction, and has the best Brier score of the three while being the least accurate at 0.5.

    Measure calibration whenever a probability is used as a probability: a risk threshold, an expected cost, an abstention rule, a confidence shown to a user, a score fed to another model. Judge calibration against human labels is on LLM-as-judge.

    4 · More than two classes: macro, micro, weighted

    With K classes each class gets its own precision, recall and F1 (one against the rest), and one number needs an average (scikit-learn user guide). Macro takes the plain mean over classes, so a 9-example class counts as much as a 76-example one. Weighted weights each class by its support (true count). Micro pools the counts first; in single-label multi-class classification every false positive for one class is a false negative for another, so micro precision, recall and F1 all equal accuracy.

    Try: switch the averaging; bar opacity is each class's weight. The rare "vehicle window" class scores F1 = 0 and drags only the macro average down.

    None is "correct". Macro answers "how good on a typical class", weighted "on a typical class, sized as in this data", micro "on a typical example". Report which, and per-class numbers when a class matters on its own.

    One set of predictions, three different "F1" numbers

    Confusion matrix (rows: true class, columns: predicted)
    Per-class F1, opacity = weight in the average

    Macro, micro and weighted F1: 0.57, 0.63 and 0.65 for the same predictions. Real data: the UCI Glass Identification set (214 glass fragments, 6 classes from 9 to 76 examples; OpenML 41), 5-fold cross-validated predictions of a standardised logistic regression (src/data_glass.py); averages checked against scikit-learn.

    5 · Regression: MAE, RMSE, R² and MAPE

    For a numeric target the errors are residuals, y − ŷ, and the metric decides how to add them up. MAE is the mean absolute residual, in the target's units; RMSE is the square root of the mean squared residual, also in those units but dominated by the largest misses, and RMSE ≥ MAE always (Willmott and Matsuura 2005 argue for MAE as the typical error; Chai and Draxler 2014 for RMSE when errors are Gaussian). R² = 1 − SSE / SST compares the squared error with always predicting the test mean: 0 is that baseline, 1 is perfect, and it goes negative for a model worse than the mean. MAPE, the mean of |y − ŷ| / |y|, is scale-free but explodes when a true value is near zero (Hyndman and Koehler 2006) and is lopsided: for a positive target and a non-negative prediction, an under-prediction costs at most 100%, an over-prediction without limit. Minimising MSE targets the conditional mean and minimising MAE the conditional median, which is why the loss and the reported metric should match (losses: Loss functions).

    Predict, then drag: one of 442 predictions gets an extra error of 1,000 (a unit slip). How far does MAE move, and how far does RMSE?

    Report MAE when every unit of error costs the same, RMSE when large misses cost disproportionately, R² to compare against the trivial model on the same data (never across datasets, since it depends on the target's variance), and a relative error only when no true value is near zero.

    One bad prediction: MAE barely notices, RMSE and R² do

    Answer: MAE rises by 1,000 / 442 = 2.3; RMSE rises from 54.6 to about 72 and R² falls from 0.498 to about 0.12. Real data: scikit-learn's diabetes set (442 patients, 10 baseline variables, target a measure of disease progression one year later, 25 to 346; Efron et al. 2004), 5-fold cross-validated ordinary least squares (src/data_reg.py): MAE 44.3, RMSE 54.6, R² 0.498, MAPE 39.7%, median absolute error 39.2; predicting the mean scores MAE 65.8, RMSE 77.0, R² 0. The perturbed patient is the one predicted most exactly (true 236, predicted 236.1). MAPE's worst case here: a patient with true value 25 predicted at 148, an error of 493%.

    6 · Ranked lists: precision@k, recall@k, MRR, MAP, nDCG

    Search, retrieval and recommendation return an ordered list per query, and the metrics look only at the top k. Precision@k is the share of the top k that is relevant and recall@k the share of all relevant items that made the top k: the threshold metrics of section 1, with the threshold at rank k. Reciprocal rank is 1 / (rank of the first relevant item), and MRR its mean over queries (Voorhees 1999, TREC-8 question answering); it ignores everything after the first hit. hit@k (also called "success@k", and "recall@k" in some dense-retrieval papers) is 1 when any relevant item is in the top k and 0 otherwise, averaged over queries: it equals recall@k when every query has exactly one relevant item and is more lenient otherwise, so check which one a paper means before comparing numbers. Average precision averages precision@i at the rank i of each relevant item, divided by the number of relevant items, and MAP is its mean over queries. nDCG handles graded relevance: DCG@k = Σi≤k gaini / log2(i + 1), divided by the same sum for the ideal ordering so that 1 is perfect (Järvelin and Kekäläinen 2002). The gain is the grade itself (scikit-learn's ndcg_score) or 2grade − 1, which favours highly relevant items (Burges et al. 2005); the two give different numbers, so say which.

    Fig. 2, step by step

    1. Ten results, graded. One query's top ten as columns in rank order, each as tall as its relevance grade (0 to 3; an illustrative list); relevant ones are lit. A fifth relevant item (grade 1) was never returned: it stands apart, outside the list, and still counts in recall and in the ideal ordering.
    2. Cut at k = 5. The glass plane keeps the top five. 3 of them are relevant, so precision@5 = 3/5 = 0.6; they are 3 of the 5 relevant items, so recall@5 = 0.6.
    3. The first hit. The first relevant item sits at rank 2, so the reciprocal rank is 1/2 = 0.5, whatever comes after it; MRR averages this number over queries.
    4. Precision at each hit. Average precision reads precision@i at the rank of each relevant item in the top five, 1/2, 2/4 and 3/5, and divides their sum by all 5 relevant items: AP@5 = (0.5 + 0.5 + 0.6) / 5 = 0.32.
    5. Discount by rank. Each grade is divided by log2(rank + 1): the grade 3 at rank 2 keeps 1.89, the grade 1 at rank 5 only 0.39. The discounted gains inside the cut, stacked, are DCG@5 = 3.141.
    6. Against the ideal order. Behind, the same five relevant grades sorted best first (3, 2, 2, 1, 1), discounted the same way and stacked: ideal DCG@5 = 6.079. nDCG@5 = 3.141 / 6.079 = 0.517.

    Try: move k. Precision@k goes up and down as hits and misses arrive; recall@k and nDCG@k only grow; reciprocal rank is fixed by rank 2.

    Two traps. Items nobody judged count as irrelevant, so a new system that finds unjudged good documents is under-scored; and the ideal DCG uses only the judged items, so nDCG is comparable only across systems on the same judgements. The same metrics on real retrieval runs (BM25 against a dense retriever on three BEIR sets, and what a reranker does to them) are on RAG and retrieval evaluation.

    One query, ten results: every list metric read off the same ranking

    An illustrative list: grades 0 to 3 at ranks 1 to 10 are 0, 3, 0, 2, 1, 0, 0, 2, 0, 0, and one more relevant item (grade 1) was never returned, so 5 are relevant. At k = 5: precision 0.6, recall 0.6, reciprocal rank 0.5, AP 0.32, nDCG@5 = 3.141 / 6.079 = 0.517 with linear gain (0.544 with 2g − 1). Every value at every k computed by src/rank_example.py and checked against scikit-learn's ndcg_score.

    7 · Text against a reference: BLEU, ROUGE, METEOR, chrF

    When the output is text, the classic metrics count what it shares with one or more human references.

    MetricMechanismOrigin, notes
    BLEUFor n = 1 to 4, the share of the output's n-grams found in the reference, each clipped to the count the reference has ("modified precision"); their geometric mean, times a brevity penalty BP = exp(1 − r/c) when the output length c is below the reference length r, else 1Machine translation; precision-oriented; defined over a whole test corpus (Papineni et al. 2002)
    ROUGE-NPrecision, recall and F1 of matching n-gramsSummarisation; recall-oriented (Lin 2004)
    ROUGE-LLongest common subsequence of the two word sequences, as precision, recall and F1Order-sensitive without requiring contiguity
    ROUGE-SSkip-bigram co-occurrence: every ordered pair of words, any gap apartAllows gaps within bigrams; rarely reported now
    METEOROne-to-one unigram alignment in stages (exact words, then Porter stems, then WordNet synonyms); Fmean = 10PR / (R + 9P); penalty 0.5 × (chunks / matches)3, where a chunk is a run of matches adjacent and in the same order in both; score = Fmean × (1 − penalty)Built to score single sentences (Banerjee and Lavie 2005)
    chrFCharacter 1- to 6-gram precision and recall (spaces removed), averaged over orders, combined as Fβ with β = 2Robust to word forms and spelling (Popović 2015)

    BLEU is a corpus metric: summed over a test set, a sentence with no 4-gram match does not zero the score. On one sentence it needs smoothing; sacreBLEU's sentence_bleu uses the "exp" method (each zero precision becomes 1 / (2k × total), Chen and Cherry 2014, method 3) and drops n-gram orders longer than the output, so never compare sentence BLEU with corpus BLEU. Tokenisation changes the number too: Post (2018) measured differences as high as 1.8 BLEU between commonly used configurations, which is why sacreBLEU fixes the tokenizer (13a) and prints a signature to quote. Every score below is computed in your browser with ports of the reference code, checked against sacrebleu 2.6.0, rouge-score 0.1.2 and NLTK 3.10.3 on these sentences and on 150 random sentence pairs (all match to 10−9; src/check_core.mjs).

    Correction to the old page: what METEOR's paper measured
    The old page said METEOR "correlates with humans better than BLEU at sentence level". The paper's only comparison with BLEU is at the system level, on the Chinese portion of the TIDES 2003 data: Pearson correlation with human judgement 0.964 for METEOR against 0.817 for BLEU (Table 1). At the segment level it reports R = 0.347 (Arabic) and 0.331 (Chinese) and compares with unigram precision, recall and F1, not with BLEU, which its authors call unfair to score per sentence (Banerjee and Lavie 2005, section 3.2).

    One candidate scored step by step, five ways

    Reference and candidates are illustrative sentences written for this page; every score is real. METEOR here runs the exact and stem stages (NLTK's meteor_score with Porter's published stemmer); the WordNet stage needs a dictionary too large for this page and is shown from NLTK for the presets.

    Try: pick a candidate and a scorer, then watch or step. Compare "Same words, clauses moved" under BLEU (it loses the 3- and 4-grams) and under METEOR (one alignment, a few chunks). Then "One word, opposite meaning" under every scorer.

    The scorer, step by step

    1. Tokenise (13a). Both sentences are split into tokens with punctuation separated, as WMT's mteval-v13a does.
    2. Unigrams. Each of the candidate's words is looked up in the reference, and each reference word can be used as many times as it occurs there ("clipping"): p1 is the share found.
    3. Bigrams. The same for pairs of adjacent words: p2.
    4. 3-grams. Runs of three: p3. Moving a clause breaks the runs that cross its edges while keeping every word.
    5. 4-grams. Runs of four: p4. A sentence with no 4-gram match would score zero, so sentence BLEU smooths a zero precision by the exp method.
    6. Geometric mean of the four precisions. exp(mean of log pn). A geometric mean is dragged down by its weakest term, so losing the long n-grams costs more than losing words.
    7. Brevity penalty. Precision alone would reward saying little: a candidate shorter than the reference is multiplied by BP = exp(1 − r/c); otherwise BP = 1.
    8. BLEU. BP × geometric mean × 100, checked against sacrebleu's sentence_bleu.

    Overlap rewards the wrong thing. A faithful paraphrase that shares few words with the reference against a copy with one word changed so that it says the opposite: every metric prefers the wrong one, the embedding metric included.

    Same meaning scores lower than opposite meaning, on all seven scores

    "After lengthy discussion on Tuesday, the panel passed the new spending plan." (same meaning)"The committee rejected the new budget after a long debate on Tuesday." (opposite meaning)

    Reference: "The committee approved the new budget after a long debate on Tuesday." BLEU and chrF on 0 to 100 divided by 100; BERTScore is the F1 rescaled with bert-score's baseline. All from the libraries.

    Your own sentences. Edit either sentence and every overlap score recomputes with the same ports (sacreBLEU's sentence BLEU and chrF, rouge-score's ROUGE, NLTK's METEOR without WordNet; ROUGE-S is implemented from Lin 2004). Change one word at a time: swap two clauses, drop "new", turn "approved" into "did not approve".

    BERTScore needs roberta-large, which cannot run in this page, so it is shown for the preset sentences only, from the library.

    All presets against the reference, every score from the libraries (table)

    Darker cells are higher on each column's own scale. Look down the columns: which candidate does each metric rank first after the copy?

    Values from sacrebleu 2.6.0, rouge-score 0.1.2, NLTK 3.10.3 (METEOR with and without WordNet) and bert-score 0.3.12 with roberta-large layer 17 (src/data_text.py); the page's live engine reproduces every non-BERTScore cell (src/check_core.mjs).

    Two NLTK details the presets expose (METEOR's synonym stage, the stemmer)
    METEOR's synonym stage in NLTK 3.10.3 looks up WordNet synonyms of the words left after the stem stage, but those words have already been replaced by their stems, so a synonym is found only when neither word changes under stemming: "fresh" for "new" matches, "sanctioned" for "approved" and "argument" for "debate" do not (the "Synonyms swapped in" preset: 0.662 without WordNet, 0.759 with). And NLTK's stemmer default (NLTK mode) differs slightly from Porter's published one; the page uses the published one and checks it word by word against NLTK in that mode. Read from the library source, nltk/translate/meteor_score.py; derived by running it.

    In 2026 these scores survive mostly as regression tests in translation and summarisation papers. The WMT22 metrics task, scored against expert MQM annotations, concluded that overlap metrics, BLEU and chrF included, "correlate poorly with human ratings" and that learned neural metrics are better and more robust (Freitag et al. 2022); Kocmi et al. (2021), with 2.3 million sentence-level human judgements over 4,380 systems, found that relying on BLEU alone led to bad deployment decisions.

    8 · Perplexity, and why it depends on the tokenizer

    Perplexity is the reciprocal geometric mean of the probabilities a model gives each token: PPL = (∏i p(wi | w<i))−1/N = exp(mean negative log-likelihood per token), the training cross entropy read as a score on held-out text. The catch is N, a count of tokens: the total log-probability of a text is comparable across models, but dividing it by a model-specific token count is not. A tokenizer that splits finely makes each token easier to predict, because the later pieces of a word follow almost surely from the first, and per-token perplexity drops without the model knowing anything more. Normalise by something the tokenizer does not choose: bits per UTF-8 byte, or perplexity per word. The Pile's authors prefer bits per byte "due to its invariance to different tokenization schemes" (Gao et al. 2020, section 3.1).

    Fig. 3, step by step

    1. The text, as bytes. "The first digits of pi are 3.14159265358979323846264338327950288." is 65 UTF-8 bytes and 7 words: the glass strip in front, one cell per byte. Bytes and words are counts no tokenizer chooses.
    2. GPT-2 cuts it into 23 tokens. Each column is one token, scored given everything before it: its width is the bytes the token covers and its height the bits per byte the model paid for it (−log2 p over the token's bytes), so its area is the token's bits. Total: 122.5 bits.
    3. SmolLM2-135M cuts it into 45 tokens and pays 50.5 bits in all: the same text, a different cut, a different total.
    4. Qwen2.5-0.5B cuts it into 45 tokens and pays 48.1 bits. The total bits of a text are comparable across models; the number of tokens is not.
    5. Perplexity per token. exp(mean nats per token), that is 2 to the power of the total bits over the token count: GPT-2 40.11, SmolLM2 2.18, Qwen2.5 2.10 (the side columns, in bits per token). The highest is 19.1 times the lowest, partly better prediction and partly finer cutting: a model that spends more tokens on the same text divides the same kind of total by a bigger N.
    6. Bits per byte. The same total bits divided by the text's bytes: GPT-2 1.884, SmolLM2 0.777, Qwen2.5 0.740. The gap is now 2.5 times: what is left is the models' prediction, not their tokenizers.

    The stage: Real per-token log-probabilities from GPT-2 (vocabulary 50,257), SmolLM2-135M (49,152) and Qwen2.5-0.5B (151,665 tokens in the tokenizer), base models in float32, each text scored after the model's own end-of-text token (src/data_ppl.py). Texts: Article 1 of the Universal Declaration of Human Rights in English and French, a three-line Python function written for this page, and the first 35 decimals of pi. Columns are capped at 10 bits per byte.

    Two more things change perplexity without changing the model: the text (GPT-2's perplexity on the French article is 11 times its perplexity on the same article in English), and the context each token gets: text longer than the window is scored with a sliding window, and a larger stride gives each token less context and a higher perplexity (Hugging Face, perplexity of fixed-length models). And low perplexity is not good generation: on GPT-2 Large, beam search output has perplexity 1.48 against 12.38 for human text, because the most probable text is degenerate (Sampling and Decoding, after Holtzman et al.). How tokenizers split languages differently is on Tokenizers.

    Entropy, cross entropy and KL behind log-loss and perplexity (owned by the root's thread 1)
    Entropy H(P) = −Σ P log P is the average bits to encode samples of P with P's own optimal code; cross entropy H(P, Q) = −Σ P log Q uses a code built for Q; their difference is the KL divergence DKL(P‖Q) = Σ P log(P/Q), the extra bits for the wrong code (asymmetric, no triangle inequality). Minimising cross entropy over Q is minimising KL, since H(P) is fixed; with one-hot labels H(P) = 0 and cross entropy = KL = the negative log-likelihood of the true class, which is log-loss (section 3) and log perplexity (above). KL is the workhorse for divergence between distributions: VAE regularisers, distillation, RLHF policy constraints. The slider is the root's "Everything is cross entropy" (Topic: ml-fundamentals, Reading, "Four threads"); as losses, Loss functions.

    9 · Embedding scores, learned metrics and judges

    BERTScore embeds both texts with a contextual encoder, takes the cosine similarity of every candidate token with every reference token, and matches greedily: precision averages, over candidate tokens, the best similarity found in the reference; recall does the same from the reference side; F1 combines them; optional idf weights make rare words count more (Zhang et al. 2019, ICLR 2020). The English default in the bert-score package is roberta-large, layer 17. Raw scores crowd into a narrow band (here 0.90 for shuffled words to 1.00 for a copy), so the package can rescale them linearly against a baseline from unrelated sentence pairs (rescale_baseline.md), (score − b) / (1 − b), which spreads the range without changing any ranking. The BERTScore view of the step animation in section 7 draws the real similarity matrix and the greedy matches.

    MoverScore replaces greedy one-to-one matching with an earth mover's distance between the two sets of embeddings, a softer many-to-one alignment (Zhao et al. 2019); it is not computed here (it needs corpus idf statistics and an optimal-transport solve, and would add a second embedding score with the same blind spot). Learned metrics such as COMET train on human quality judgements; they are the "neural metrics" WMT22 found better than overlap. For open-ended LLM output, evaluation has largely moved to LLM judges and task benchmarks, a measuring instrument with its own biases and calibration: Topic: evaluation-and-llm-judges, judge design on LLM-as-judge, and two paper pages with data: RocketEval (a small judge grading checklists re-ranks a leaderboard almost exactly) and Re-grading six physics benchmarks (what expert re-grading does to headline scores).

    10 · How much to trust a number: error bars

    A test set is a sample, so every metric on it has sampling error. For accuracy p on n examples the standard error is √(p(1 − p)/n): at 80% on 872 sentences that is 1.4 points, so a 95% interval is about ±2.7. On the hero's data naive Bayes is 1.1 points more accurate than logistic regression, and the paired 95% interval (−1.0 to +3.4 points, src/recompute.py) still crosses zero: on 872 examples a 1-point gap is inside the noise. For metrics with no simple formula (F1, AUC, BLEU) the bootstrap resamples the test set with replacement and reads the interval off the spread (Efron 1979); comparing two models on the same items, resample the pairs (Koehn 2004 for MT; Miller 2024 for LLM evals). Report the interval, say what was resampled (sentences, documents, users: whatever was drawn independently), and size the test set before collecting it. Paired tests, clustered questions and sample-size planning are owned by Eval statistics.

    The paired bootstrap on these two classifiers (slider: test-set size)

    Try: shrink the test set and watch the paired interval (upper line) stay narrower than the unpaired one: the paired difference cancels each sentence's shared difficulty.

    Real per-sentence correctness of the two SST-2 classifiers at threshold 0.5; the first n sentences of a fixed random order (seed 0). Percentile intervals from a seeded resampler; src/recompute.py runs the same bootstrap in NumPy with another seed (at n = 872, paired 95% interval −1.0 to +3.4 points, the figure quoted above), while this widget's first seed at 2,000 resamples gives −1.1 to +3.2: two seeds disagreeing by a few tenths of a point is the resampling noise of the bootstrap itself.

    Before reporting a metric: ten checks (each from a section above)
    • Accuracy on an imbalanced task: on the rare-positive subset "always negative" scores 90.5%, above the real classifier; report MCC or per-class precision and recall, and the base rate.
    • Threshold chosen on the test set: picking the threshold that maximises F1 or MCC on the data you then report inflates the score; choose it on validation data, or report a threshold-free metric.
    • ROC-AUC read as "good" when positives are rare: it barely moves with prevalence; look at AUPRC or precision at the recall you need.
    • A trapezoidal PR area called "average precision": linear interpolation in PR space is optimistic (Davis and Goadrich 2006).
    • A confident score treated as a probability: naive Bayes here is the more accurate model and has twice the log-loss; check a reliability diagram and the Brier score first.
    • "F1" without macro, micro or weighted: 0.57, 0.63 and 0.65 on the same glass predictions.
    • RMSE without MAE, or R² across datasets: one unit slip moves RMSE far more than MAE; R² depends on the target's variance.
    • BLEU across papers: tokenisation alone moves it by up to 1.8 points; quote the sacreBLEU signature.
    • Overlap scores trusted on meaning: a one-word negation beats a faithful paraphrase on BLEU, ROUGE, METEOR, chrF and BERTScore.
    • Perplexity across tokenizers or texts: compare bits per byte, or perplexity only with the same tokenizer, text and context.