71 / 90

Day 71: Quantitative Evaluation Metrics & Statistical Confidence

Derive Exact Match, Token F1, ROUGE-L, compute log-likelihood probabilities, and estimate non-parametric bootstrap confidence intervals.

Self-Directed Learning & Python Engineering Foundations 480 active minutes (8 hours)
01 120 min

Exact Match (EM) and Token-Level Precision, Recall, and F1

Agent-Assisted Engineering Check

Prerequisites

Day 70 Benchmark Task Formulations and Python text processing.

Learning Objective

Mathematically formulate Exact Match (EM) and token-level Precision, Recall, and F1 with canonical SQuAD text normalization.

Instructions

Study source: within this activity's existing reading/practice time, use Hugging Face LLM Evaluation Guidebook (legacy edition), contents/automated-benchmarks/designing-your-automatic-evaluation.md: Choosing a metric; contents/troubleshooting/troubleshooting-reproducibility.md, then explain one connection to the local task in your own words. Keep the local exercise and acceptance checks; use its original explanation if the external source is unavailable. 1. Analyze Exact Match (EM): binary score (1.0 or 0.0) indicating whether the normalized prediction matches ground truth exactly.
2. Study standard SQuAD normalization (Rajpurkar et al. 2016): (a) Lowercase text, (b) Strip punctuation, (c) Remove English articles ('a', 'an', 'the'), and (d) Collapse consecutive whitespace.
3. Derive token-level multiset metrics: let P and T be collections of tokens from normalized prediction and ground truth. Common tokens = sum of min(count_P(w), count_T(w)) for w in P cap T.
4. Precision = Common / |P|; Recall = Common / |T|; F1 = 2 * Precision * Recall / (Precision + Recall). Handle boundary condition |P| == 0 or |T| == 0: if both empty, F1=1.0; if only one empty, F1=0.0.

Practice & Prediction Log

Implement a pure Python function compute_token_f1(prediction, ground_truth) that applies full SQuAD normalization and computes Exact Match and Token F1, returning a dictionary {'em': float, 'f1': float}.

Independent Mastery Criterion

Derive and code canonical token-level F1 and EM passing all multiset tokenization edge cases.

Authoritative Source Resources & Provenance

linking CC BY-NC-SA 4.0 noncommercial share-alike

Hugging Face LLM Evaluation Guidebook (legacy edition)

Author: Hugging Face evaluation-guidebook contributors | Original Source Link ↗

Relevant Section / Range: contents/automated-benchmarks/designing-your-automatic-evaluation.md: Choosing a metric; contents/troubleshooting/troubleshooting-reproducibility.md

Verified Version & Date: Public edition checked 2026-11-01; moving pages may change

Selection Rationale:

Teaching-oriented evaluation design and reproducibility guidance complements the benchmark papers. Stable methodological chapters only; not a current tooling/version reference.

Source Prerequisites:

Held-out data, basic language-model metrics and experimental comparisons.

Safe Fallback (Offline Resilience):

Use the original localized explanations, exercises and checks already present in this activity; no external account or purchase is required for that fallback.

Compared Candidate Sources & Selection Analysis (2)
HELM ↗ compared_alternative [Open Access / CC BY 4.0]

Retained for the multi-metric framework; the guidebook makes practical choices easier to teach.

LM Evaluation Harness ↗ compared_alternative [MIT]

Useful implementation cross-check; tool configuration alone does not teach metric choice or evaluator limitations.

linking Open Access / CC BY-SA 4.0 share-alike

SQuAD: 100,000+ Questions for Machine Comprehension of Text

Author: Pranav Rajpurkar, Jian Zhang, Konstantin Lopyrev, Percy Liang | Original Source Link ↗

Relevant Section / Range: Section 6.1 Model Evaluation (Exact match and macro-averaged F1)

Verified Version & Date: EMNLP 2016 / arXiv:1606.05250v3 (Verified: 2026-10-30)

Selection Rationale:

Defines the standard NLP Exact Match (EM) and token-level Macro/Micro F1 evaluation metrics, establishing standard text normalization rules (lowercasing, punctuation stripping, article removal).

Source Prerequisites:

Tokenization, text normalization, precision, recall, and harmonic mean F1.

Safe Fallback (Offline Resilience):

Exact normalization code, multiset token intersection logic, and F1 calculations are completely coded in lesson exercises.

Compared Candidate Sources & Selection Analysis (2)

Adds unanswerable questions; SQuAD 1.1 formalizes the foundational token F1 and EM mathematical definitions.

Conversational multi-turn QA; SQuAD provides a widely adopted implementation of normalized token F1.

linking CC BY-NC-SA 3.0 (ACL Anthology, pre-2016 material) noncommercial share-alike

BLEU: a Method for Automatic Evaluation of Machine Translation

Author: Kishore Papineni, Salim Roukos, Todd Ward, Wei-Jing Zhu | Original Source Link ↗

Relevant Section / Range: Section 2.1.1 Modified n-gram precision on blocks of text; Section 2.3 BLEU details

Verified Version & Date: ACL 2002 Anthology (Verified: 2026-10-30)

Selection Rationale:

Foundational literature introducing modified n-gram precision and brevity penalties, providing the mathematical contrast between precision-oriented n-gram clipping and recall-oriented sequence metrics.

Source Prerequisites:

N-gram precision, modified n-gram clipping, brevity penalty.

Safe Fallback (Offline Resilience):

N-gram clipping algorithms, geometric mean precision, and brevity penalty formulas are completely implemented in lesson code.

Compared Candidate Sources & Selection Analysis (2)
Banerjee & Lavie. METEOR: An Automatic Metric for MT Evaluation with Improved Correlation with Human Judgments ↗ compared_alternative [CC BY-NC-SA 3.0 (ACL Anthology, pre-2016 material)]

Incorporates stemming and WordNet synonymy; BLEU is the fundamental n-gram precision baseline required for quantitative comparison.

Popović. chrF: character n-gram F-score for automatic MT evaluation ↗ compared_alternative [CC BY-NC-SA 3.0 (ACL Anthology, pre-2016 material)]

Character-level n-gram F-score; Papineni BLEU provides the historic foundation for token-based precision clipping.

02 120 min

Sequence Overlap Metrics: ROUGE-L and Longest Common Subsequence

Independent Mastery Check (no AI assistance).

Prerequisites

Day 71 Activity 1 and dynamic programming.

Learning Objective

Implement the Longest Common Subsequence (LCS) dynamic programming algorithm and derive sequence-level ROUGE-L precision, recall, and F-measure.

Instructions

1. Review ROUGE (Lin 2004): ROUGE-N evaluates n-gram recall, while ROUGE-L measures Longest Common Subsequence without requiring contiguous token matches.
2. Formulate the dynamic programming LCS algorithm: for sequences X (length m) and Y (length n), DP table dp[i][j] = dp[i-1][j-1] + 1 if X[i-1] == Y[j-1] else max(dp[i-1][j], dp[i][j-1]) with complexity O(m * n).
3. Compute ROUGE-L: Recall R_lcs = LCS(X, Y) / m; Precision P_lcs = LCS(X, Y) / n; F_lcs = ((1 + beta^2) * R_lcs * P_lcs) / (R_lcs + beta^2 * P_lcs). Typically beta = 1.0 or DUC standard beta = 1.2.
4. Analyze limitations: ROUGE-L is invariant to factual inversion (e.g. inserting 'not' drops LCS by only 1 token while completely reversing meaning).

Practice & Prediction Log

Write a pure Python function compute_rouge_l(candidate, reference, beta=1.0) that builds the 2D DP matrix, computes the exact LCS length, and returns precision, recall, and F-score.

Independent Mastery Criterion

Calculate exact ROUGE-L scores using DP table formulations and explain vulnerability to lexical negation.

Authoritative Source Resources & Provenance

linking CC BY-NC-SA 3.0 (ACL Anthology, pre-2016 material) noncommercial share-alike

ROUGE: A Package for Automatic Evaluation of Summaries

Author: Chin-Yew Lin | Original Source Link ↗

Relevant Section / Range: Section 3 ROUGE-L: Longest Common Subsequence

Verified Version & Date: ACL 2004 Workshop Anthology (Verified: 2026-10-30)

Selection Rationale:

Primary literature establishing ROUGE-N and ROUGE-L (Longest Common Subsequence), deriving sequence-level recall, precision, and F-measure without requiring consecutive n-gram matches.

Source Prerequisites:

Longest Common Subsequence (LCS), dynamic programming, recall-oriented evaluation.

Safe Fallback (Offline Resilience):

Dynamic programming LCS algorithms and ROUGE-L scoring equations are completely self-contained in lesson code.

Compared Candidate Sources & Selection Analysis (2)

Embedding similarity based metric; ROUGE-L provides exact deterministic surface-form sequence overlap without model weights.

Optimal transport metric; ROUGE-L is the required universal baseline for summary and instruction evaluation.

linking Apache License 2.0 / Open Access

A Call for Clarity in Reporting BLEU Scores

Author: Matt Post | Original Source Link ↗

Relevant Section / Range: Section 2 Problem Description

Verified Version & Date: WMT 2018 / arXiv:1804.08771v1 (Verified: 2026-10-30)

Selection Rationale:

Critical paper on metric reproducibility, proving how inconsistent tokenization schemes and smoothing parameters alter reported metrics by multiple percentage points, demanding standardized evaluation strings.

Source Prerequisites:

Tokenization standardization, evaluation parameters, string normalization pipelines.

Safe Fallback (Offline Resilience):

Standardized token normalization pipelines, deterministic tokenizer flags, and signature strings are implemented in curriculum exercises.

Compared Candidate Sources & Selection Analysis (2)
Google Research rouge-score Python library ↗ compared_alternative [Apache 2.0]

Specific ROUGE implementation; Post et al. provides the overarching reproducibility doctrine for NLP metric reporting.

Hugging Face evaluate library ↗ compared_alternative [Apache 2.0]

Unified evaluation framework; Post establishes the critical methodology for eliminating hidden tokenization divergence.

03 120 min

Held-Out Log-Likelihood Evaluation & Perplexity Under Length Penalties

Agent-Assisted Engineering Check

Prerequisites

Day 71 Activities 1-2 and autoregressive probability distributions.

Learning Objective

Compute conditional log-likelihoods over candidate continuations, apply length normalization penalties, and derive held-out perplexity.

Instructions

1. Formulate autoregressive sequence likelihood: log P(Y | X) = sum_{t=1}^T log P(y_t | X, y_{2. Calculate Perplexity: PPL(Y | X) = exp(- (1 / T) * sum_{t=1}^T log P(y_t | X, y_{3. Length normalization problem: raw sum log P(Y | X) inherently penalizes longer candidate completions because each additional token adds negative log-probability. Plain average (1/T) conversely penalizes concise, precise answers.
4. Apply length penalty normalization: Score(Y | X) = log P(Y | X) / ((5 + T)^alpha / (5 + 1)^alpha), where alpha in [0.6, 1.0] balances length preference.
5. Address prior token bias: compute unconditional continuation score log P(Y) and use normalized margin Score_norm = log P(Y|X) - log P(Y).

Practice & Prediction Log

Implement rank_with_length_penalty(candidates, alpha=0.7), where candidates maps each of 4 answer labels to (total_log_prob, token_length). Use the total log-probabilities [-1.2, -0.8, -0.5, -2.1] with token lengths [1, 2, 3, 5], and rank the candidates by length-normalized score under alpha=0.7.

Independent Mastery Criterion

Apply length penalty exponents and conditional log-likelihood calculations across multi-choice evaluation splits.

Authoritative Source Resources & Provenance

linking Open Access / OpenAI Public Publication

Language Models are Unsupervised Multitask Learners

Author: Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, Ilya Sutskever | Original Source Link ↗

Relevant Section / Range: Section 3.1 Language Modeling

Verified Version & Date: OpenAI Technical Report 2019 (Verified: 2026-10-30)

Selection Rationale:

Foundational demonstration of zero-shot task transfer via log-likelihood evaluation over target candidate completions, formalizing length normalization and held-out perplexity scoring.

Source Prerequisites:

Autoregressive conditional likelihood, cross-entropy loss, perplexity exponentiation.

Safe Fallback (Offline Resilience):

Conditional log-likelihood equations, length normalization factors, and held-out cross-entropy calculations are fully derived in lesson material.

Compared Candidate Sources & Selection Analysis (2)

Focuses on empirical power-law loss curves; Radford et al. establishes the zero-shot log-likelihood task evaluation protocol.

Optimal compute scaling; Radford provides the fundamental zero-shot conditional probability formulation.

linking arXiv non-exclusive license / Open Access

The Curious Case of Neural Text Degeneration

Author: Ari Holtzman, Jan Buys, Li Du, Maxwell Forbes, Yejin Choi | Original Source Link ↗

Relevant Section / Range: Section 4.2 Perplexity

Verified Version & Date: ICLR 2020 / arXiv:1904.09751v2 (Verified: 2026-10-30)

Selection Rationale:

Primary source introducing Nucleus (Top-p) sampling and analyzing the failure of greedy decoding (loops, repetition).

Source Prerequisites:

Softmax probabilities, cumulative probability distributions from Days 25-27 and 41-42.

Safe Fallback (Offline Resilience):

Top-p truncation algorithms and worked probability cutoffs are completely explained in the lesson.

Compared Candidate Sources & Selection Analysis (2)

Introduces top-k sampling; Holtzman et al. dynamic nucleus threshold is compared directly against top-k.

Hugging Face Generation Strategies Guide ↗ compared_alternative [Apache 2.0]

Practical library guide; Holtzman provides the foundational mathematical reasoning.

04 120 min

Assessment: Non-Parametric Bootstrap Confidence Intervals on Small Slices

Independent Mastery Check (no AI assistance).

Prerequisites

Day 71 Activities 1-3.

Learning Objective

Implement Bradley Efron's non-parametric bootstrap resampling to construct empirical 95% confidence intervals and paired hypothesis tests for small evaluation slices.

Instructions

1. Analyze statistical noise in small benchmark splits: on an evaluation slice of N=50 or 100 samples, a 3% or 4% difference between Model A and Model B is frequently within random sampling error.
2. Study non-parametric bootstrap (Efron 1979): from original sample S of size N, draw B=10,000 replicate samples S*_b with replacement of size N.
3. Compute metric theta*_b (e.g. Accuracy or Mean F1) on each replicate sample.
4. Construct empirical percentile 95% Confidence Interval: [q_0.025, q_0.975].
5. Implement Paired Bootstrap Significance Testing (Koehn 2004): for paired predictions (A_i, B_i), compute delta*_b = metric(B*_b) - metric(A*_b). The empirical p-value is the fraction of resamples where delta*_b <= 0.

Practice & Prediction Log

Write a Python function bootstrap_confidence_interval(scores, num_resamples=10000, alpha=0.05) that computes the empirical mean and 95% percentile confidence bounds [lower, upper]. Test it on a 50-item score slice.

Independent Mastery Criterion

Calculate non-parametric bootstrap confidence intervals and paired p-values, preventing misleading claims of superiority on small test slices.

Authoritative Source Resources & Provenance

linking Institute of Mathematical Statistics copyright / Academic linking only

Bootstrap Methods: Another Look at the Jackknife

Author: Bradley Efron | Original Source Link ↗

Relevant Section / Range: N/A

Verified Version & Date: The Annals of Statistics 1979 (Verified: 2026-10-30)

Selection Rationale:

Original statistical work introducing non-parametric bootstrap resampling, enabling rigorous confidence interval estimation without Gaussian distribution assumptions.

Source Prerequisites:

Empirical distributions, sampling with replacement, confidence intervals, standard error.

Safe Fallback (Offline Resilience):

Bootstrap resampling algorithms with replacement, empirical percentile confidence interval bounds, and standard error formulas are coded in Python.

Compared Candidate Sources & Selection Analysis (2)

Requires strong normality assumptions; Efron's non-parametric bootstrap applies directly to non-Gaussian NLP accuracy metrics.

Tests sharp null hypotheses under exchangeability; bootstrap directly yields confidence intervals for point estimates.

linking CC BY-NC-SA 3.0 (ACL Anthology, pre-2016 material) noncommercial share-alike

Statistical Significance Tests for Machine Translation Evaluation

Author: Philipp Koehn | Original Source Link ↗

Relevant Section / Range: Section 5 Bootstrap Resampling and Section 6 Paired Bootstrap Resampling

Verified Version & Date: EMNLP 2004 Anthology (Verified: 2026-10-30)

Selection Rationale:

Pioneering application of paired bootstrap resampling in NLP evaluation, demonstrating how to compute statistical significance and prevent false claims of model superiority on small test slices.

Source Prerequisites:

Paired bootstrap resampling, hypothesis testing, p-values, test set variance.

Safe Fallback (Offline Resilience):

Paired bootstrap hypothesis testing, delta confidence intervals, and empirical p-value computation are completely implemented in lesson code.

Compared Candidate Sources & Selection Analysis (2)
Dror et al. The Hitchhiker's Guide to Testing Statistical Significance in NLP ↗ compared_alternative [CC BY 4.0 (ACL Anthology, 2016 or later)]

Modern comprehensive survey of significance testing; Koehn 2004 is the established, accessible paired bootstrap paper in NLP.

Berg-Kirkpatrick et al. An Empirical Investigation of Statistical Significance in NLP ↗ compared_alternative [CC BY-NC-SA 3.0 (ACL Anthology, pre-2016 material)]

Evaluates optimizer vs test-set randomness; Koehn provides the direct, actionable paired test-set bootstrap.