71 / 90

第71日: 定量的評価指標と統計的信頼区間の算出

完全一致(Exact Match)、トークンF1、ROUGE-Lを導出し、対数尤度を算出、非復元抽出ブートストラップによる信頼区間を推定する。

自律学習手法と Python エンジニアリング基礎 480 分(8時間)
01 120 分

完全一致(Exact Match)とトークン単位の適合率・再現率・F1スコア

Agent支援エンジニアリングチェック

前提条件

第70日のベンチマークタスク設計およびPythonテキスト処理。

学習目標

SQuAD標準のテキスト正規化パイプラインを用い、完全一致(EM)とトークン単位の適合率・再現率・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)の定義: 正規化後の予測文字列と正解文字列が100%一致する場合に1.0、それ以外を0.0とする二値指標。
2. SQuAD標準正規化(Rajpurkar et al. 2016)の手順: (a) 小文字化、(b) 句読点・記号の除去、(c) 英語冠詞('a', 'an', 'the')の削除、(d) 連続空白の単一化。
3. トークン多重集合(Multiset)に基づく指標計算: 予測トークン列Pと正解トークン列Tの重複度を考慮した共通トークン数を Counter(P) & Counter(T) により算出。
4. 適合率 = 共通数 / |P|、再現率 = 共通数 / |T|、F1 = 2 * P * R / (P + R)。空文字列の境界条件(双方が空ならF1=1.0、片方のみ空ならF1=0.0)を漏れなく処理する。

演習と予測記録

SQuAD正規化を適用し、完全一致およびトークンF1を計算して {'em': float, 'f1': float} を返却するPython関数 compute_token_f1 を実装してください。

独立習得基準

多重集合トークン交差とSQuAD正規化に基づくトークンF1およびEMを正確に実装できること。

公式ソースリソースと権利証跡

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

Hugging Face LLM Evaluation Guidebook (legacy edition)

著者・提供機関: Hugging Face evaluation-guidebook contributors | オリジナル出所URL ↗

該当セクション・タイムスタンプ: 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 | オリジナル出所URL ↗

該当セクション・タイムスタンプ: 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 | オリジナル出所URL ↗

該当セクション・タイムスタンプ: 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 / m、適合率 P_lcs = LCS / n、F値 F_lcs = ((1 + beta^2) * R * P) / (R + beta^2 * P)。標準では beta=1.0。
4. 限界の認識: ROUGE-Lは文脈反転(否定詞 'not' の挿入)に対してスコアが1トークン分しか低下せず、事実性の反転を検知できない。

演習と予測記録

外部ライブラリに依存せず、動的計画法テーブルを直接構築してROUGE-Lの適合率・再現率・F値を算出するPython関数 compute_rouge_l を実装してください。

独立習得基準

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 | オリジナル出所URL ↗

該当セクション・タイムスタンプ: 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 | オリジナル出所URL ↗

該当セクション・タイムスタンプ: 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 分

評価用データにおける対数尤度・パープレキシティと長さペナルティの設計

Agent支援エンジニアリングチェック

前提条件

第71日アクティビティ1〜2および自己回帰確率モデル。

学習目標

候補選択肢に対する条件付き対数尤度を算出し、長さペナルティによる正規化とパープレキシティを評価する。

手順

1. 自己回帰系列尤度の定式化: log P(Y | X) = sum_{t=1}^T log P(y_t | X, y_{2. パープレキシティ(PPL)の導出: PPL = exp(- (1 / T) * sum log P(y_t | X, y_{3. 長さペナルティの必要性: 対数確率の単純総和は長い候補ほど負の項が累積し不利になり、単純平均(1/T)は短く無難な候補を過大評価する。
4. 指数型長さペナルティの適用: Score(Y | X) = log P(Y | X) / ((5 + T)^alpha / (5 + 1)^alpha)。alpha in [0.6, 1.0] で長さ選好を調整する。
5. トークン事前バイアスの補正: 無条件生成対数尤度 log P(Y) を差し引いた差分スコア Score_norm = log P(Y|X) - log P(Y) を用いて特定トークンの出現頻度偏りを排除する。

演習と予測記録

rank_with_length_penalty(candidates, alpha=0.7) を実装してください。candidates は 4 つの選択肢ラベルを (total_log_prob, token_length) に対応付ける辞書です。合計対数確率 [-1.2, -0.8, -0.5, -2.1]、トークン長 [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 | オリジナル出所URL ↗

該当セクション・タイムスタンプ: 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 | オリジナル出所URL ↗

該当セクション・タイムスタンプ: 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 分

実践評価: 小規模評価スライスにおける非パラメトリックブートストラップ信頼区間

独立習得チェック(AI 支援なし)

前提条件

第71日アクティビティ1〜3。

学習目標

Bradley Efronの非パラメトリックブートストラップ復元抽出法を実装し、95%信頼区間と対応のある有意差検定を実行する。

手順

1. 小規模スライスにおける統計的ノイズの危険性: N=50〜100件程度のテストセットでは、3〜4%の精度向上は見かけ上の標本抽出誤差である可能性が高い。
2. 非パラメトリックブートストラップ(Efron 1979)の手順: 元の標本サイズNから復元抽出(重複を許す抽出)によりB=10,000個の再標本 S*_b を生成する。
3. 各再標本に対して評価指標 theta*_b(精度や平均F1など)を算出する。
4. パーセンタイル法による95%信頼区間の構築: 再標本指標の 2.5% 点と 97.5% 点を抽出し [CI_lower, CI_upper] を確定する。
5. 対応のあるブートストラップ検定(Koehn 2004): モデルAとモデルBの同一標本での差 delta*_b を計算し、delta*_b <= 0 となる割合から経験的p値を導出する。

演習と予測記録

50件のスコア配列を受け取り、10,000回のブートストラップ抽出により平均値と95%信頼区間 [lower, upper] を返却するPython関数 bootstrap_confidence_interval を実装してください。

独立習得基準

非パラメトリックブートストラップによる信頼区間およびp値を算出し、小規模スライスにおける過剰主張を科学的に防止できること。

公式ソースリソースと権利証跡

linking Institute of Mathematical Statistics copyright / Academic linking only

Bootstrap Methods: Another Look at the Jackknife

著者・提供機関: Bradley Efron | オリジナル出所URL ↗

該当セクション・タイムスタンプ: 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 | オリジナル出所URL ↗

該当セクション・タイムスタンプ: 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.