42 / 90

第 42 天:損失、訓練紀律與每週綜合複習

把 softmax 機率變成交叉熵損失,觀察使用固定劃分與固定種子的規範訓練迴圈,誠實面對過擬合與數值不穩定反例,再以獨立的回憶評估結束本週。複習時間計入 480 分鐘台帳。

模型與訓練 480 分鐘主動學習時間(8 小時專注學習)
01 120 分鐘

交叉熵損失:從機率到純量驚異度

Agent 輔助工程檢查

前置要求

第 41 天的前向傳播與 softmax;自然對數。

學習目標

定義負對數似然損失,對範例分布完成計算,並相對均勻基線做出解釋。

操作指引

必做任務:目標索引 t 的損失為 L = -ln p_t。昨天的前向傳播對上下文 ('a','b')(真實下一符號為 'c',索引 3)輸出 p = [0.229291, 0.209107, 0.306433, 0.255169]。計算 L,並與均勻基線 ln(4) = 1.386294 比較,判斷該模型是否優於隨機猜測。選做任務:換用 log2 把 L 表示成位元。

自主實作與記錄

1. L = -ln(0.255169) = ?
2. 對 3 類別的 logit z = [1.0, 0.5, -0.5]、目標索引 0,計算 softmax 機率與 NLL。
3. 本例中困惑度 exp(L) 意味著什麼?

獨立掌握標準

兩個損失都算到小數點後 4 位以上,給出與均勻基線的比較,並把困惑度正確解釋為有效詞彙量。

權威來源資源與權利證明

linking MIT License (repository) / Standard YouTube License (video, subtitle rights unknown) Video subtitles have unknown distribution rights and are not imported

makemore: Character-level language models on names.txt

作者 / 機構: Andrej Karpathy | 原始出處連結 ↗

對應章節 / 時間戳: Loss computation segment: negative log-likelihood over the minibatch

驗證版本與日期: Repository state verified 2026-10-30; lecture published 2022

入選理由:

Standard beginner walkthrough of the Bengio-style MLP language model; the MIT-licensed reference implementation pairs with a stepwise derivation that matches the Days 40-42 worked numbers exactly.

來源前置條件:

Python basics, matrix multiplication, and the Day 37-39 tokenization and n-gram context

安全回退方案(離線彈性):

All forward-pass arithmetic, shapes, parameter counts, and loss values are reproduced as original hand-worked examples in the lesson text; no video, subtitle, or transcript is required.

對比候選資源與選型分析 (3)
Yoshua Bengio et al.: A Neural Probabilistic Language Model (JMLR 2003) ↗ compared_selected_co_primary [JMLR open access (author-retained copyright)]

The original architecture paper; selected jointly as the theoretical citation while Makemore supplies the stepwise implementation walkthrough.

Stanford CS336: Language Modeling from Scratch ↗ compared_deferred [No license declared (the repository has no LICENSE file, so all rights are reserved by default)]

Strong PyTorch rigor but assumes fluent tensor programming; deferred to the Days 43-60 pretraining blocks rather than the first embedding contact.

3Blue1Brown: Neural Networks series ↗ compared_alternative [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

Strong visual intuition for network mechanics but covers image classification rather than embedding tables and next-token language modeling; retained as optional supplementary viewing.

linking JMLR open access (author-retained copyright)

A Neural Probabilistic Language Model

作者 / 機構: Yoshua Bengio, Rejean Ducharme, Pascal Vincent, Christian Jauvin | 原始出處連結 ↗

對應章節 / 時間戳: Section 2 (training criterion: maximizing the log-likelihood, equivalently minimizing NLL)

驗證版本與日期: JMLR Volume 3 (2003); verified 2026-10-30

入選理由:

The original paper introducing jointly learned word feature vectors and the neural probabilistic language model; grounds the curriculum's embedding and MLP derivations in the primary literature.

來源前置條件:

Probability basics and linear algebra

安全回退方案(離線彈性):

Every worked derivation in the lessons is self-contained and offline-complete; the paper is further reading only.

對比候選資源與選型分析 (3)
Andrej Karpathy: Let's build makemore (MLP) ↗ compared_selected_co_primary [MIT (repository code) / Standard YouTube License (video)]

Selected jointly: Makemore reproduces this architecture at character scale with MIT-licensed code; the paper supplies the original formalism and the n-gram comparison framing.

Strong textbook coverage of n-grams through neural LMs; kept as secondary reading because the primary derivation follows the original paper's notation.

Foundational for embedding geometry but trains on context-prediction objectives rather than the full next-token probabilistic model studied this week; revisited in later representation blocks.

02 120 分鐘

訓練迴圈觀察:固定劃分下的損失、梯度與更新

獨立掌握檢查

前置要求

完成上一活動;如受阻請使用列出的復原連結。

學習目標

描述一步訓練(前向 → 損失 → 反向 → 更新)以及固定 train/dev/test 劃分與固定種子的作用;預測損失移動方向,但不承諾任何閾值。

操作指引

必做任務:回憶第 34-36 天的梯度步。一次迭代取一個 (上下文, 目標) 小批次,執行前向傳播,對 NLL 取平均,反向傳播,然後按 p <- p - lr * dL/dp 更新全部參數。記錄你預測的損失曲線形狀,再說明固定的 80/10/10 train/dev/test 劃分與固定種子為比較保證了什麼。選做任務:預測學習率過大時曲線會怎樣。

自主實作與記錄

1. 按順序列出一步訓練的四個階段。
2. 若 train 損失持續下降而 dev 損失上升,說明什麼?
3. 為什麼固定種子與劃分能讓兩個模型變體的比較誠實可信?

獨立掌握標準

學習者按順序列出四個階段,把 dev 上升解釋為過擬合,並說明固定種子/劃分提供可比性——不虛構損失保證。

權威來源資源與權利證明

linking MIT License (repository) / Standard YouTube License (video, subtitle rights unknown) Video subtitles have unknown distribution rights and are not imported

makemore: Character-level language models on names.txt

作者 / 機構: Andrej Karpathy | 原始出處連結 ↗

對應章節 / 時間戳: Training loop segment: minibatch SGD, learning-rate schedule, train/dev split discipline

驗證版本與日期: Repository state verified 2026-10-30; lecture published 2022

入選理由:

Standard beginner walkthrough of the Bengio-style MLP language model; the MIT-licensed reference implementation pairs with a stepwise derivation that matches the Days 40-42 worked numbers exactly.

來源前置條件:

Python basics, matrix multiplication, and the Day 37-39 tokenization and n-gram context

安全回退方案(離線彈性):

All forward-pass arithmetic, shapes, parameter counts, and loss values are reproduced as original hand-worked examples in the lesson text; no video, subtitle, or transcript is required.

對比候選資源與選型分析 (3)
Yoshua Bengio et al.: A Neural Probabilistic Language Model (JMLR 2003) ↗ compared_selected_co_primary [JMLR open access (author-retained copyright)]

The original architecture paper; selected jointly as the theoretical citation while Makemore supplies the stepwise implementation walkthrough.

Stanford CS336: Language Modeling from Scratch ↗ compared_deferred [No license declared (the repository has no LICENSE file, so all rights are reserved by default)]

Strong PyTorch rigor but assumes fluent tensor programming; deferred to the Days 43-60 pretraining blocks rather than the first embedding contact.

3Blue1Brown: Neural Networks series ↗ compared_alternative [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

Strong visual intuition for network mechanics but covers image classification rather than embedding tables and next-token language modeling; retained as optional supplementary viewing.

linking JMLR open access (author-retained copyright)

A Neural Probabilistic Language Model

作者 / 機構: Yoshua Bengio, Rejean Ducharme, Pascal Vincent, Christian Jauvin | 原始出處連結 ↗

對應章節 / 時間戳: Sections 3-4 (parameter optimization and experimental methodology)

驗證版本與日期: JMLR Volume 3 (2003); verified 2026-10-30

入選理由:

The original paper introducing jointly learned word feature vectors and the neural probabilistic language model; grounds the curriculum's embedding and MLP derivations in the primary literature.

來源前置條件:

Probability basics and linear algebra

安全回退方案(離線彈性):

Every worked derivation in the lessons is self-contained and offline-complete; the paper is further reading only.

對比候選資源與選型分析 (3)
Andrej Karpathy: Let's build makemore (MLP) ↗ compared_selected_co_primary [MIT (repository code) / Standard YouTube License (video)]

Selected jointly: Makemore reproduces this architecture at character scale with MIT-licensed code; the paper supplies the original formalism and the n-gram comparison framing.

Strong textbook coverage of n-grams through neural LMs; kept as secondary reading because the primary derivation follows the original paper's notation.

Foundational for embedding geometry but trains on context-prediction objectives rather than the full next-token probabilistic model studied this week; revisited in later representation blocks.

03 120 分鐘

反例:過擬合、數值不穩定與 bigram 基線

Agent 輔助工程檢查

前置要求

完成上一活動;如受阻請使用列出的復原連結。

學習目標

構造誠實的反例:小資料上的記憶化、softmax 的 exp 溢位,以及能勝過未訓練網路的簡單計數基線。

操作指引

必做任務:三個反例。(1) 記憶化:在 4 符號玩具語料上,模型可以把 train NLL 壓向 0,而 dev NLL 停在 ln(4) = 1.386294 附近。(2) 不穩定:logit [1000,999,998]——未平移的 exp 在 float64 溢位,平移後的 softmax 為 [0.665241, 0.244728, 0.090031]。(3) 基線:若語料中 'b' 之後 4 次有 3 次接 'c',bigram 給出 p(c|b) = 0.75。選做任務:描述一種連訓練好的 MLP 也會輸給 bigram 的情形。

自主實作與記錄

1. 復現 logit [1000,999,998] 的平移 softmax 分布。
2. 計算 p(c|b) = 0.75 與未見對 p = 0.25 的 bigram NLL。
3. 寫一句誠實的話,比較未訓練 MLP 與 bigram 基線。

獨立掌握標準

以正確數值復現全部三個反例,並寫出同時涵蓋記憶化侷限與真實優勢成立條件的誠實比較句。

權威來源資源與權利證明

linking MIT License (repository) / Standard YouTube License (video, subtitle rights unknown) Video subtitles have unknown distribution rights and are not imported

makemore: Character-level language models on names.txt

作者 / 機構: Andrej Karpathy | 原始出處連結 ↗

對應章節 / 時間戳: Overfitting and split evaluation segments; comparison with the bigram counting baseline

驗證版本與日期: Repository state verified 2026-10-30; lecture published 2022

入選理由:

Standard beginner walkthrough of the Bengio-style MLP language model; the MIT-licensed reference implementation pairs with a stepwise derivation that matches the Days 40-42 worked numbers exactly.

來源前置條件:

Python basics, matrix multiplication, and the Day 37-39 tokenization and n-gram context

安全回退方案(離線彈性):

All forward-pass arithmetic, shapes, parameter counts, and loss values are reproduced as original hand-worked examples in the lesson text; no video, subtitle, or transcript is required.

對比候選資源與選型分析 (3)
Yoshua Bengio et al.: A Neural Probabilistic Language Model (JMLR 2003) ↗ compared_selected_co_primary [JMLR open access (author-retained copyright)]

The original architecture paper; selected jointly as the theoretical citation while Makemore supplies the stepwise implementation walkthrough.

Stanford CS336: Language Modeling from Scratch ↗ compared_deferred [No license declared (the repository has no LICENSE file, so all rights are reserved by default)]

Strong PyTorch rigor but assumes fluent tensor programming; deferred to the Days 43-60 pretraining blocks rather than the first embedding contact.

3Blue1Brown: Neural Networks series ↗ compared_alternative [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

Strong visual intuition for network mechanics but covers image classification rather than embedding tables and next-token language modeling; retained as optional supplementary viewing.

linking JMLR open access (author-retained copyright)

A Neural Probabilistic Language Model

作者 / 機構: Yoshua Bengio, Rejean Ducharme, Pascal Vincent, Christian Jauvin | 原始出處連結 ↗

對應章節 / 時間戳: Section 4 (comparison with n-gram baselines and generalization discussion)

驗證版本與日期: JMLR Volume 3 (2003); verified 2026-10-30

入選理由:

The original paper introducing jointly learned word feature vectors and the neural probabilistic language model; grounds the curriculum's embedding and MLP derivations in the primary literature.

來源前置條件:

Probability basics and linear algebra

安全回退方案(離線彈性):

Every worked derivation in the lessons is self-contained and offline-complete; the paper is further reading only.

對比候選資源與選型分析 (3)
Andrej Karpathy: Let's build makemore (MLP) ↗ compared_selected_co_primary [MIT (repository code) / Standard YouTube License (video)]

Selected jointly: Makemore reproduces this architecture at character scale with MIT-licensed code; the paper supplies the original formalism and the n-gram comparison framing.

Strong textbook coverage of n-grams through neural LMs; kept as secondary reading because the primary derivation follows the original paper's notation.

Foundational for embedding geometry but trains on context-prediction objectives rather than the full next-token probabilistic model studied this week; revisited in later representation blocks.

04 120 分鐘

每週綜合複習:獨立回憶與端到端評估

獨立掌握檢查

前置要求

完成活動 42-01 至 42-03;按需複習第 40-41 天。

學習目標

無輔助回憶第 40-42 天整條流水線,重算保留上下文的損失,並為每個遺漏的知識點記錄復原連結。

操作指引

必做任務:闔上書本。畫出帶全部形狀的流水線:索引 → C 的列 → 串接 → W1/b1 → tanh → W2/b2 → softmax → NLL。然後用第 41 天的機率,計算上下文 ('b','a')、真實下一符號 'a'(索引 1)的損失。完成知識測驗。若有遺漏,記錄你將回到第 40 天、第 41 天還是復原連結第 35 天。選做任務:重新推導 V=27 的均勻基線。

自主實作與記錄

1. 目標索引 1 時 p = [0.290410, 0.237875, 0.220627, 0.251087] 的損失。
2. 憑記憶重建微型模型的參數台帳(合計 39)。
3. 陳述神經語言模型誠實優於 bigram 的兩個條件。

客觀知識測驗:損失、訓練與誠實比較

請回答以下診斷題目檢驗掌握情況。提交前請誠實聲明你的輔助條件。

聲明輔助條件

說明:無 AI 輔助屬於誠實聲明條件,非平台監控或強制檢測手段。

1.

在 4 符號任務上 NLL 低於 ln(4) = 1.386294 的模型,平均而言:

2.

在 V=4 任務上 train NLL 接近 0 而 dev NLL 接近 1.39,最可能說明:

3.

比較兩個模型之前為什麼要固定隨機種子和 train/dev/test 劃分?

作答應證與歷史記錄

    獨立掌握標準

    無輔助算出損失 1.436009 並重建台帳,畫出形狀正確的流水線,陳述誠實的優於基線的條件,並為任何缺口指定復原連結。

    權威來源資源與權利證明

    linking MIT License (repository) / Standard YouTube License (video, subtitle rights unknown) Video subtitles have unknown distribution rights and are not imported

    makemore: Character-level language models on names.txt

    作者 / 機構: Andrej Karpathy | 原始出處連結 ↗

    對應章節 / 時間戳: Complete makemore MLP lecture: embedding lookup through loss evaluation

    驗證版本與日期: Repository state verified 2026-10-30; lecture published 2022

    入選理由:

    Standard beginner walkthrough of the Bengio-style MLP language model; the MIT-licensed reference implementation pairs with a stepwise derivation that matches the Days 40-42 worked numbers exactly.

    來源前置條件:

    Python basics, matrix multiplication, and the Day 37-39 tokenization and n-gram context

    安全回退方案(離線彈性):

    All forward-pass arithmetic, shapes, parameter counts, and loss values are reproduced as original hand-worked examples in the lesson text; no video, subtitle, or transcript is required.

    對比候選資源與選型分析 (3)
    Yoshua Bengio et al.: A Neural Probabilistic Language Model (JMLR 2003) ↗ compared_selected_co_primary [JMLR open access (author-retained copyright)]

    The original architecture paper; selected jointly as the theoretical citation while Makemore supplies the stepwise implementation walkthrough.

    Stanford CS336: Language Modeling from Scratch ↗ compared_deferred [No license declared (the repository has no LICENSE file, so all rights are reserved by default)]

    Strong PyTorch rigor but assumes fluent tensor programming; deferred to the Days 43-60 pretraining blocks rather than the first embedding contact.

    3Blue1Brown: Neural Networks series ↗ compared_alternative [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

    Strong visual intuition for network mechanics but covers image classification rather than embedding tables and next-token language modeling; retained as optional supplementary viewing.

    linking JMLR open access (author-retained copyright)

    A Neural Probabilistic Language Model

    作者 / 機構: Yoshua Bengio, Rejean Ducharme, Pascal Vincent, Christian Jauvin | 原始出處連結 ↗

    對應章節 / 時間戳: Sections 1-4 (complete model and evaluation overview)

    驗證版本與日期: JMLR Volume 3 (2003); verified 2026-10-30

    入選理由:

    The original paper introducing jointly learned word feature vectors and the neural probabilistic language model; grounds the curriculum's embedding and MLP derivations in the primary literature.

    來源前置條件:

    Probability basics and linear algebra

    安全回退方案(離線彈性):

    Every worked derivation in the lessons is self-contained and offline-complete; the paper is further reading only.

    對比候選資源與選型分析 (3)
    Andrej Karpathy: Let's build makemore (MLP) ↗ compared_selected_co_primary [MIT (repository code) / Standard YouTube License (video)]

    Selected jointly: Makemore reproduces this architecture at character scale with MIT-licensed code; the paper supplies the original formalism and the n-gram comparison framing.

    Strong textbook coverage of n-grams through neural LMs; kept as secondary reading because the primary derivation follows the original paper's notation.

    Foundational for embedding geometry but trains on context-prediction objectives rather than the full next-token probabilistic model studied this week; revisited in later representation blocks.