71 / 90

第 71 天:定量评测指标与统计置信度分析

数学推导完全匹配(EM)、Token F1、ROUGE-L 指标,计算 held-out 集对数似然概率,并运用非参数自助法估计小样本置信区间。

自学方法与 Python 工程基础 480 分钟有效研习(8 小时)
01 120 分钟

完全匹配(EM)与 Token 级精确率、召回率及 F1 值

Agent 辅助工程检查

前置要求

第 70 天基准任务构建与 Python 文本处理基础。

学习目标

数学推导完全匹配(EM)与基于 SQuAD 文本规范化的多重集合 Token 级 F1 指标并编写实现代码。

操作指引

学习来源:在本活动现有的阅读与练习时段内,参考 Hugging Face LLM Evaluation Guidebook (legacy edition) 的 contents/automated-benchmarks/designing-your-automatic-evaluation.md: Choosing a metric; contents/troubleshooting/troubleshooting-reproducibility.md,用自己的话解释一处与本地任务的联系。保留现有练习与验收检查;若外部资料无法访问,使用课程自写的解释。1. 掌握完全匹配(Exact Match, EM):二值化判定指标,当且仅当模型预测文本在规范化后与真实标签字符串完全一致时输出 1.0,否则输出 0.0。
2. 学习标准 SQuAD 规范化流程(Rajpurkar et al. 2016):(a) 全文转小写、(b) 剔除所有标点符号、(c) 剔除英语常见冠词('a'、'an'、'the')、(d) 合并多余连续空格。
3. 推导基于多重集合(Multiset)的 Token 级指标:设 P 和 T 分别为预测与参考 Token 列表。共通 Token 计数 = sum(min(count_P(w), count_T(w)))。
4. 计算 Precision = 共通数 / |P|;Recall = 共通数 / |T|;F1 = 2 * P * R / (P + R)。严谨处理边界:若两者均为空字符串则 F1=1.0;若仅有一方为空则 F1=0.0。

自主演练与记录

编写 Python 函数 compute_token_f1(prediction, ground_truth),严格执行 SQuAD 文本规范化,计算并返回包含 {'em': float, 'f1': float} 的字典结果。

独立掌握标准

独立推导并编码实现多重集合 Token F1 与 EM 指标,100% 覆盖各类空值与异常边界条件。

权威源资源与权利证明

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

Hugging Face LLM Evaluation Guidebook (legacy edition)

作者 / 机构: Hugging Face evaluation-guidebook contributors | 原始出处链接 ↗

对应章节 / 时间戳: contents/automated-benchmarks/designing-your-automatic-evaluation.md: Choosing a metric; contents/troubleshooting/troubleshooting-reproducibility.md

验证版本与日期: Public edition checked 2026-11-01; moving pages may change

入选理由:

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

来源前置条件:

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

安全回退方案(离线弹性):

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

对比候选资源与选型分析 (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

作者 / 机构: Pranav Rajpurkar, Jian Zhang, Konstantin Lopyrev, Percy Liang | 原始出处链接 ↗

对应章节 / 时间戳: Section 6.1 Model Evaluation (Exact match and macro-averaged F1)

验证版本与日期: EMNLP 2016 / arXiv:1606.05250v3 (Verified: 2026-10-30)

入选理由:

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).

来源前置条件:

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

安全回退方案(离线弹性):

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

对比候选资源与选型分析 (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

作者 / 机构: Kishore Papineni, Salim Roukos, Todd Ward, Wei-Jing Zhu | 原始出处链接 ↗

对应章节 / 时间戳: Section 2.1.1 Modified n-gram precision on blocks of text; Section 2.3 BLEU details

验证版本与日期: ACL 2002 Anthology (Verified: 2026-10-30)

入选理由:

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.

来源前置条件:

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

安全回退方案(离线弹性):

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

对比候选资源与选型分析 (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 分钟

序列重合度指标:ROUGE-L 与最长公共子序列(LCS)

独立掌握检查(无 AI 辅助)

前置要求

第 71 天活动 1 及动态规划(DP)基础。

学习目标

通过动态规划实现最长公共子序列(LCS)算法,并推导 ROUGE-L 查准率、查全率与 F 度量。

操作指引

1. 学习 ROUGE 指标家族(Lin 2004):ROUGE-N 衡量连续 n-gram 召回率,而 ROUGE-L 采用最长公共子序列(LCS),无需词对连续即可评估跨度语序结构。
2. 动态规划求解 LCS:设参考序列 X(长度 m)与候选序列 Y(长度 n)。构建 DP 表 dp[i][j] = dp[i-1][j-1] + 1(X[i-1] == Y[j-1] 时)或 max(dp[i-1][j], dp[i][j-1])(不相等时)。时间复杂度 O(m * n)。
3. 计算 ROUGE-L:查全率 R_lcs = LCS(X, Y) / m;查准率 P_lcs = LCS(X, Y) / n;F 度量 F_lcs = ((1 + beta^2) * R * P) / (R + beta^2 * P)。常规任务取 beta=1.0。
4. 辨析核心缺陷:ROUGE-L 对否定语义反转极度不敏感(例如插入单个否定词 'not' 仅使 LCS 长度减少 1,而句意完全相反)。

自主演练与记录

不依赖外部三方库,使用纯 Python 与原生二维列表构建动态规划矩阵,编写 compute_rouge_l(candidate, reference, beta=1.0) 函数并输出精确评测分值。

独立掌握标准

手写动态规划求解 LCS 并推导 ROUGE-L,能够清晰剖析其在语义否定下的盲区。

权威源资源与权利证明

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

ROUGE: A Package for Automatic Evaluation of Summaries

作者 / 机构: Chin-Yew Lin | 原始出处链接 ↗

对应章节 / 时间戳: Section 3 ROUGE-L: Longest Common Subsequence

验证版本与日期: ACL 2004 Workshop Anthology (Verified: 2026-10-30)

入选理由:

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.

来源前置条件:

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

安全回退方案(离线弹性):

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

对比候选资源与选型分析 (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

作者 / 机构: Matt Post | 原始出处链接 ↗

对应章节 / 时间戳: Section 2 Problem Description

验证版本与日期: WMT 2018 / arXiv:1804.08771v1 (Verified: 2026-10-30)

入选理由:

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

来源前置条件:

Tokenization standardization, evaluation parameters, string normalization pipelines.

安全回退方案(离线弹性):

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

对比候选资源与选型分析 (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 分钟

Held-Out 验证集对数似然评测与长度惩罚困惑度

Agent 辅助工程检查

前置要求

第 71 天活动 1 至 2 及自回归条件概率建模。

学习目标

计算候选续写序列的自回归对数似然,应用长度指数归一化惩罚,并推导困惑度(Perplexity)。

操作指引

1. 自回归生成序列对数似然公式:log P(Y | X) = sum_{t=1}^T log P(y_t | X, y_{2. 困惑度(Perplexity, PPL)公式:PPL = exp(- (1 / T) * sum log P(y_t | X, y_{3. 长度偏差痛点:直接累加 log P(Y | X) 会惩罚长序列(每个额外 Token 都是负数累加);而简单的算术平均 (1/T) 则会导致模型倾向于极短、平庸的通用词汇。
4. 长度指数惩罚归一化:Score(Y | X) = log P(Y | X) / ((5 + T)^alpha / (5 + 1)^alpha),其中 alpha in [0.6, 1.0] 控制长度偏好平滑度。
5. 消除先验 Token 偏置:计算无条件生成对数似然 log P(Y),使用边际分数 Score_norm = log P(Y|X) - log P(Y) 消除高频词伪影。

自主演练与记录

编写 Python 函数 rank_with_length_penalty(candidates, alpha=0.7),其中 candidates 把 4 个候选选项的标签映射到 (total_log_prob, token_length)。使用累积对数似然 [-1.2, -0.8, -0.5, -2.1] 与 Token 长度 [1, 2, 3, 5],按 alpha=0.7 的长度惩罚归一化分值从高到低排序。

独立掌握标准

熟练计算自回归对数似然、长度惩罚因子与验证集困惑度,准确完成多选排序任务。

权威源资源与权利证明

linking Open Access / OpenAI Public Publication

Language Models are Unsupervised Multitask Learners

作者 / 机构: Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, Ilya Sutskever | 原始出处链接 ↗

对应章节 / 时间戳: Section 3.1 Language Modeling

验证版本与日期: OpenAI Technical Report 2019 (Verified: 2026-10-30)

入选理由:

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

来源前置条件:

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

安全回退方案(离线弹性):

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

对比候选资源与选型分析 (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

作者 / 机构: Ari Holtzman, Jan Buys, Li Du, Maxwell Forbes, Yejin Choi | 原始出处链接 ↗

对应章节 / 时间戳: Section 4.2 Perplexity

验证版本与日期: ICLR 2020 / arXiv:1904.09751v2 (Verified: 2026-10-30)

入选理由:

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

来源前置条件:

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

安全回退方案(离线弹性):

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

对比候选资源与选型分析 (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 分钟

综合评估:小样本评测切片上的非参数自助法(Bootstrap)置信区间

独立掌握检查(无 AI 辅助)

前置要求

第 71 天活动 1 至活动 3。

学习目标

实现 Bradley Efron 非参数自助法(Bootstrap)重采样,构建 95% 置信区间并执行配对假设检验。

操作指引

1. 警惕小切片评测统计噪音:在 N=50 或 100 样本的小切片上,两个模型间 3% 或 4% 的准确率差异通常完全落在随机采样误差范围内。
2. 非参数 Bootstrap 原理(Efron 1979):从规模为 N 的原始评测集合中,执行有放回抽样(sampling with replacement),构建 B=10,000 次重采样样本集 S*_b。
3. 在每次重采样副本上重新计算目标指标 theta*_b(如准确率或 Macro F1)。
4. 构建经验分位数 95% 置信区间:提取重采样分布的 2.5% 与 97.5% 分位点 [CI_lower, CI_upper]。
5. 实现配对显著性检验(Koehn 2004):同步计算模型 B 与 A 的差值 delta*_b = metric(B*_b) - metric(A*_b)。经验 p 值即为 delta*_b <= 0 的重采样频次占比。

自主演练与记录

编写 Python 函数 bootstrap_confidence_interval(scores, num_resamples=10000, alpha=0.05),对输入的样本打分数组执行 10,000 次自助法重采样,返回均值与 95% 置信区间。

独立掌握标准

掌握非参数自助法重采样与置信区间构建方法,能够在小样本评测中科学辨识虚假优势。

权威源资源与权利证明

linking Institute of Mathematical Statistics copyright / Academic linking only

Bootstrap Methods: Another Look at the Jackknife

作者 / 机构: Bradley Efron | 原始出处链接 ↗

对应章节 / 时间戳: N/A

验证版本与日期: The Annals of Statistics 1979 (Verified: 2026-10-30)

入选理由:

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

来源前置条件:

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

安全回退方案(离线弹性):

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

对比候选资源与选型分析 (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

作者 / 机构: Philipp Koehn | 原始出处链接 ↗

对应章节 / 时间戳: Section 5 Bootstrap Resampling and Section 6 Paired Bootstrap Resampling

验证版本与日期: EMNLP 2004 Anthology (Verified: 2026-10-30)

入选理由:

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.

来源前置条件:

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

安全回退方案(离线弹性):

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

对比候选资源与选型分析 (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.