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.