53 / 90

第53日:モデル評価プロトコル:検証損失ギャップ、過学習とパープレキシティ(PPL)

訓練損失と検証損失の乖離曲線を測定し、過学習とデータリークを診断し、未知テスト集合のパープレキシティを計算し、誠実な評価規律を確立する。

モデル・事前学習とLoRA 480分の集中学習(8時間)
01 120 分

評価プロトコル:訓練損失と検証損失のギャップ分析

Agent支援工学分析

前提条件

第51日訓練ループと第42日交差エントロピー。

学習目標

訓練ステップ進行に伴う訓練・検証損失の乖離を測定し、過学習の変曲点を定義する。

手順

torch.no_grad() を用いて勾配計算を行わずに、eval_iters 個のバッチにわたってモデルを評価する estimate_loss() を定義せよ。以下の値をプロットまたは表にまとめよ:Step 0: train 4.10, val 4.12;Step 500: train 2.20, val 2.25;Step 1500: train 1.10, val 1.95。step 1000 を汎化プラトー(generalization plateau)としてマークせよ。

演習と予測記録

1. なぜ評価は no_grad と eval の下で実行すべきか?
2. 訓練損失低下に対し検証損失が上昇し始める現象は何を意味するか?
3. 最良チェックポイント選定の基準は何か?

独立習得基準

標準評価規約を理解し、検証損失によるチェックポイント選定原則を説明できること。

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

linking MIT

nanoGPT: model.py architecture implementation

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

該当セクション・タイムスタンプ: model.py: class GPT forward(idx, targets): wte + wpe, Blocks, ln_f, lm_head (returns cross-entropy loss when targets are given)

検証バージョンと日付: Git master (Verified: 2026-10-30)

選定理由:

Compact historical code reference for the named implementation functions; CS336 spring2025 provides the lead component exercises. Do not infer top-p, atomic persistence or cloud budget enforcement from nanoGPT.

ソース前提知識:

Python, PyTorch, and Day 43-45 attention fundamentals.

安全フォールバック(オフライン回復性):

Local models and classes in the curriculum mirror nanoGPT semantics directly.

比較対象候補リソースと選定評価 (2)
GPT-2 TensorFlow source (OpenAI) ↗ compared_alternative [Modified MIT License]

Original legacy TensorFlow 1.x code; nanoGPT provides clean modern PyTorch equivalent.

Llama 2 / 3 PyTorch source (Meta) ↗ compared_alternative [Llama 2 Community License]

Includes advanced production features (RoPE, GQA), but nanoGPT's simplicity is ideal for the core Days 46-48 assembly.

linking CC BY 4.0

Google Machine Learning Crash Course

著者・提供機関: Google for Developers | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Modules: Training and Test Sets; Overfitting; Classification accuracy

検証バージョンと日付: Current online edition (Verified: 2026-10-30)

選定理由:

Industrial, beginner-legible treatment of training/test splitting and overfitting; complements d2l.ai's mathematical framing.

ソース前提知識:

Basic algebra; short self-contained modules.

安全フォールバック(オフライン回復性):

Split discipline, leakage rules, and metric definitions are fully explained inside the lesson; the course is further reading.

比較対象候補リソースと選定評価 (2)
Dive into Deep Learning (d2l.ai) ↗ compared_selected_for_day29 [CC BY-SA 4.0 (book text) / modified MIT (sample code)]

Co-primary: deeper mathematical coverage of model selection, generalization, and optimization for the mathematics-track capstone.

scikit-learn: Model Evaluation documentation ↗ compared_alternative [BSD-3-Clause]

Normative reference once learners call sklearn; kept as an alternative because these days teach evaluation protocol before library usage.

02 120 分

未知テキストにおけるパープレキシティ(PPL)の厳密測定

Agent支援工学分析

前提条件

活動01および第42日PPL基礎。

学習目標

テスト分割の交差エントロピー損失を測定し、PPL = exp(loss) を導出する。

手順

ホールドアウトのテスト分割(100,000 トークン)が与えられたとする:(1) 平均交差エントロピー損失 L_val = 1.6094 nats を計算せよ。(2) パープレキシティ Perplexity = exp(1.6094) = 5.0 を計算せよ。(3) V=50,000 のランダム推測による基準(ランダムベースライン)と比較せよ:L = ln(50000) approx 10.82、PPL = 50,000。

演習と予測記録

1. 検証損失 2.3026 nats のときPPLはいくつか?
2. PPL=10 は次トークン予測の不確実性として何を意味するか?
3. 訓練PPLのみを報告することが不誠実である理由は何か?

独立習得基準

交差エントロピーからPPLへの換算を正確に行い、その不確実性の意味を説明できること。

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

linking MIT

nanoGPT: model.py architecture implementation

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

該当セクション・タイムスタンプ: model.py: class GPT forward(idx, targets): wte + wpe, Blocks, ln_f, lm_head (returns cross-entropy loss when targets are given)

検証バージョンと日付: Git master (Verified: 2026-10-30)

選定理由:

Compact historical code reference for the named implementation functions; CS336 spring2025 provides the lead component exercises. Do not infer top-p, atomic persistence or cloud budget enforcement from nanoGPT.

ソース前提知識:

Python, PyTorch, and Day 43-45 attention fundamentals.

安全フォールバック(オフライン回復性):

Local models and classes in the curriculum mirror nanoGPT semantics directly.

比較対象候補リソースと選定評価 (2)
GPT-2 TensorFlow source (OpenAI) ↗ compared_alternative [Modified MIT License]

Original legacy TensorFlow 1.x code; nanoGPT provides clean modern PyTorch equivalent.

Llama 2 / 3 PyTorch source (Meta) ↗ compared_alternative [Llama 2 Community License]

Includes advanced production features (RoPE, GQA), but nanoGPT's simplicity is ideal for the core Days 46-48 assembly.

linking Free author-published draft chapter Draft text is not reproduced; linking only

Speech and Language Processing, 3rd ed. draft, Chapter 3: N-gram Language Models

著者・提供機関: Daniel Jurafsky, James H. Martin | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Sections 3.1-3.4: n-gram counts, maximum-likelihood estimation, Laplace smoothing, and perplexity

検証バージョンと日付: Draft of 2026-08-19 (Verified: 2026-10-30)

選定理由:

Standard reference text for n-gram definitions, count normalization, smoothing, and perplexity used across Day 38.

ソース前提知識:

Basic probability

安全フォールバック(オフライン回復性):

All formulas and worked tables in the curriculum are self-contained and verified by execution.

比較対象候補リソースと選定評価 (2)
Chen & Goodman: An Empirical Study of Smoothing Techniques for Language Modeling ↗ compared_alternative [CC BY-NC-SA 3.0 (ACL Anthology, pre-2016 material)]

Detailed smoothing survey but far beyond the add-one scope of a first n-gram day; optional further reading.

MIT OCW 6.863J Natural Language Processing ↗ compared_alternative [CC BY-NC-SA 4.0]

Solid academic lecture treatment but less current and less integrated with executable count tables than the SLP3 draft.

03 120 分

過学習・データ暗記・データリークの深層診断

Agent支援工学分析

前提条件

活動53-01および53-02。

学習目標

トークン順シャッフルによるリーク、語彙重複、正規化不足を特定する。

手順

3つのシナリオを検証せよ:(A) 系列に分割する前にトークンをシャッフルすること(自己回帰の因果性を壊し、隣接する単語が分割をまたいで漏洩する=データリーク)。(B) プロンプトと検証データの間での n-gram の重複。(C) 極小データセットでドロップアウトをゼロに設定すること。

演習と予測記録

1. トークン配列のシャッフルがなぜ壊滅的なリークを引き起こすか?
2. 真の汎化と機械的暗記をどう見分けるか?
3. 正しい分割順序(文書分割が先か、トークン化が先か)を述べよ。

独立習得基準

トークンレベルのリーク機構を指摘し、文書単位分割の規約を説明できること。

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

linking CC BY 4.0

Google Machine Learning Crash Course

著者・提供機関: Google for Developers | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Modules: Training and Test Sets; Overfitting; Classification accuracy

検証バージョンと日付: Current online edition (Verified: 2026-10-30)

選定理由:

Industrial, beginner-legible treatment of training/test splitting and overfitting; complements d2l.ai's mathematical framing.

ソース前提知識:

Basic algebra; short self-contained modules.

安全フォールバック(オフライン回復性):

Split discipline, leakage rules, and metric definitions are fully explained inside the lesson; the course is further reading.

比較対象候補リソースと選定評価 (2)
Dive into Deep Learning (d2l.ai) ↗ compared_selected_for_day29 [CC BY-SA 4.0 (book text) / modified MIT (sample code)]

Co-primary: deeper mathematical coverage of model selection, generalization, and optimization for the mathematics-track capstone.

scikit-learn: Model Evaluation documentation ↗ compared_alternative [BSD-3-Clause]

Normative reference once learners call sklearn; kept as an alternative because these days teach evaluation protocol before library usage.

linking MIT

nanoGPT: model.py architecture implementation

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

該当セクション・タイムスタンプ: N/A

検証バージョンと日付: Git master (Verified: 2026-10-30)

選定理由:

Compact historical code reference for the named implementation functions; CS336 spring2025 provides the lead component exercises. Do not infer top-p, atomic persistence or cloud budget enforcement from nanoGPT.

ソース前提知識:

Python, PyTorch, and Day 43-45 attention fundamentals.

安全フォールバック(オフライン回復性):

Local models and classes in the curriculum mirror nanoGPT semantics directly.

比較対象候補リソースと選定評価 (2)
GPT-2 TensorFlow source (OpenAI) ↗ compared_alternative [Modified MIT License]

Original legacy TensorFlow 1.x code; nanoGPT provides clean modern PyTorch equivalent.

Llama 2 / 3 PyTorch source (Meta) ↗ compared_alternative [Llama 2 Community License]

Includes advanced production features (RoPE, GQA), but nanoGPT's simplicity is ideal for the core Days 46-48 assembly.

04 120 分

独立モデル汎化とチェックポイント評価チェック

完全自立閉本テスト

前提条件

活動01-03の完了。

学習目標

過学習の生じた評価ログを客観的に診断し、誠実な分析報告書を作成する。

手順

tiny Shakespeare 上で学習させた10Mパラメータモデルの評価トレースが与えられたとする:訓練損失 0.85、検証損失 1.75。0.90 の損失ギャップを明示的に認める、誠実な診断サマリを作成せよ。

演習と予測記録

1. 状態は未学習、適合、過学習のどれか?
2. 適用すべき正則化(Weight Decay、Dropout、Early Stopping)は何か?
3. 公開報告書に含めるべき誠実な要約文を1行で書け。

独立習得基準

不利な結果を粉飾せず、技術的に正確で誠実な評価を行えること。

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

linking MIT

nanoGPT: model.py architecture implementation

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

該当セクション・タイムスタンプ: N/A

検証バージョンと日付: Git master (Verified: 2026-10-30)

選定理由:

Compact historical code reference for the named implementation functions; CS336 spring2025 provides the lead component exercises. Do not infer top-p, atomic persistence or cloud budget enforcement from nanoGPT.

ソース前提知識:

Python, PyTorch, and Day 43-45 attention fundamentals.

安全フォールバック(オフライン回復性):

Local models and classes in the curriculum mirror nanoGPT semantics directly.

比較対象候補リソースと選定評価 (2)
GPT-2 TensorFlow source (OpenAI) ↗ compared_alternative [Modified MIT License]

Original legacy TensorFlow 1.x code; nanoGPT provides clean modern PyTorch equivalent.

Llama 2 / 3 PyTorch source (Meta) ↗ compared_alternative [Llama 2 Community License]

Includes advanced production features (RoPE, GQA), but nanoGPT's simplicity is ideal for the core Days 46-48 assembly.

linking CC BY 4.0

Google Machine Learning Crash Course

著者・提供機関: Google for Developers | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Modules: Training and Test Sets; Overfitting; Classification accuracy

検証バージョンと日付: Current online edition (Verified: 2026-10-30)

選定理由:

Industrial, beginner-legible treatment of training/test splitting and overfitting; complements d2l.ai's mathematical framing.

ソース前提知識:

Basic algebra; short self-contained modules.

安全フォールバック(オフライン回復性):

Split discipline, leakage rules, and metric definitions are fully explained inside the lesson; the course is further reading.

比較対象候補リソースと選定評価 (2)
Dive into Deep Learning (d2l.ai) ↗ compared_selected_for_day29 [CC BY-SA 4.0 (book text) / modified MIT (sample code)]

Co-primary: deeper mathematical coverage of model selection, generalization, and optimization for the mathematics-track capstone.

scikit-learn: Model Evaluation documentation ↗ compared_alternative [BSD-3-Clause]

Normative reference once learners call sklearn; kept as an alternative because these days teach evaluation protocol before library usage.