41 / 90

第 41 日:ニューラル言語モデルの順伝播

Makemore 式 MLP を手計算で端から端まで追跡する:埋め込みルックアップ、文脈連結、tanh 隠れ層、出力ロジット、数値安定な softmax。各活動で予測・観察・復習・回復を記録する。

モデルと訓練 480 分の能動学習時間(8 時間の集中学習)
01 120 分

ニューラル言語モデルのパイプライン:インデックスからプレアクティベーションへ

Agent支援エンジニアリング確認

前提条件

第 40 日の埋め込みルックアップと文脈連結、第 34-36 日の MLP の仕組み。

学習目標

インデックス → C の行 → 連結 x → 隠れ層プレアクティベーションという全パイプラインをたどり、入力ベクトルとプレアクティベーションベクトルを手計算する。

手順

必須作業:第 40 日のテーブル C と文脈 ('a','b') を使い、x = [0.2, -0.1, -0.4, 0.5] とする。今日の重みは固定:W1 = [[0.5,-0.2,0.1],[0.3,0.4,-0.3],[-0.1,0.2,0.6],[0.2,-0.5,0.4]]、b1 = [0.1,-0.1,0.0]。各隠れプレアクティベーション pre_j = sum_i x_i * W1[i][j] + b1[j] を計算する。トレースを確認する前に予測値を記録する。任意作業:pre_1 に最も大きく影響する入力座標を 1 つ予測する。

演習と予測記録

1. 上の x と W1 で pre_0、pre_1、pre_2 を計算し、すべての積を示す。
2. プレアクティベーションのどれかがちょうど 0 になるか予測する。
3. 生のシンボルから pre までのパイプライン段階を順に挙げる。

独立習得基準

手計算のプレアクティベーションが各積を示して [0.31, -0.51, 0.01] と一致し、学習者がメモなしでパイプライン段階を順に説明できる。

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

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

該当セクション・タイムスタンプ: Segment wiring the MLP forward pass: C[X] -> hidden tanh layer -> output logits

検証バージョンと日付: 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 | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Section 2 (the mapping g: context feature vectors to next-word probabilities)

検証バージョンと日付: 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 分

手計算の隠れ層:tanh と非線形性の意義

独立習得確認

前提条件

前の活動を完了すること。詰まった場合は記載の回復リンクを使う。

学習目標

tanh を要素ごとに適用して隠れベクトルを正確に計算し、2 つの線形写像の間に非線形性が必要な理由を正当化する。

手順

必須作業:h = tanh(pre) を要素ごとに適用。tanh(0.31) = 0.300437、tanh(-0.51) = -0.469945、tanh(0.01) = 0.010000 を使い、少なくとも 1 つを計算機か Python の math.tanh で検算する。次に縮退の問いに答える:活性化が tanh ではなく恒等写像なら、2 つの線形写像は何に縮約されるか?任意作業:tanh(5.0) と tanh(-5.0) を計算して飽和を観察する。

演習と予測記録

1. 隠れベクトル h を書く。
2. tanh は飽和する:tanh(5.0) を小数 4 桁で求め、飽和が非常に大きなプレアクティベーションに何を意味するか述べる。
3. 縮退を証明する:恒等活性化なら h = x*W1、z = h*W2 となるとき、z を x だけで表す。

独立習得基準

h を小数 6 桁まで正確に計算し、飽和の観察と、積み重ねた線形写像が 1 つの線形写像に縮約するという 1 行の証明を示せる。

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

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

該当セクション・タイムスタンプ: Hidden layer construction segment: h = tanh(X W1 + b1) with shape annotations

検証バージョンと日付: 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 | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Sections 2-3 (hidden layer with tanh units and free parameters)

検証バージョンと日付: 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 分

ロジット、数値安定な softmax、出力分布

Agent支援エンジニアリング確認

前提条件

前の活動を完了すること。詰まった場合は記載の回復リンクを使う。

学習目標

ロジット z = h*W2 + b2 を計算し、最大値シフト版 softmax を適用して次シンボル分布を得て、反例で安定化テクニックを説明する。

手順

必須作業:W2 = [[0.2,-0.1,0.3,0.1],[0.4,0.2,-0.2,0.0],[-0.3,0.1,0.5,-0.4]]、b2 = [0.05,-0.05,0.02,0.0]。昨日の h で z = h*W2 + b2 を計算する。次に softmax:m = max(z) を引き、指数化し、正規化する。反例:ロジット [1000,999,998] では素朴な exp(1000) が float64 でオーバーフローするが、シフト版は [0.665241, 0.244728, 0.090031] を返す。任意作業:任意の定数 c について softmax(z - c) = softmax(z) を証明する。

演習と予測記録

1. 4 つのロジット z を計算する。
2. m = max(z) として exp(z_j - m)、正規化の和、p を計算する。
3. p の和が 1 になることを確認する。
4. 最大値を引いても数学的に何も変わらない理由を一文で述べる。

独立習得基準

z と p を小数 6 桁まで正確に計算し、和が 1 であることを検算し、最大値シフトの不変性を正しく論じられる。

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

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

該当セクション・タイムスタンプ: Output layer and loss segment: logits = h W2 + b2, softmax probabilities, cross-entropy loss

検証バージョンと日付: 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 | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Section 2 (softmax output guarantees positive probabilities summing to one)

検証バージョンと日付: 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 分

独立習得確認:未使用文脈での完全順伝播

独立習得確認

前提条件

活動 41-01 から 41-03 を完了すること。

学習目標

新しい文脈 ('b','a') について順伝播全体を自力で再現し、予測シンボルを正直に特定する。

手順

必須作業:教科書を閉じる。文脈 ('b','a') = インデックス [2,1] について、同じ C、W1、b1、W2、b2 で順伝播全体を計算し、参考解答を開く前に次シンボルを予測する。任意作業:真の次シンボルが 'a'(インデックス 1)の場合の交差エントロピー損失を求める — 第 42 日で必要になる。

演習と予測記録

文脈 ('b','a') について:
1. 連結入力 x。
2. プレアクティベーションと隠れベクトル h。
3. ロジット z。
4. 確率 p と argmax シンボル。

客観的理解度チェック:順伝播と softmax

以下の設問に解答して理解度を確認してください。提出前に利用した補助条件を誠実に申告してください。

申告補助条件

注記: AI不使用は誠実な申告条件であり、監視や強制検知ではありません。

1.

数値安定な softmax が指数化の前に全ロジットから max(z) を引く理由は?

2.

間に非線形活性化を挟まない 2 層の線形層は、何と同等か:

3.

シンボル ['.','a','b','c'] 上の p = [0.290410, 0.237875, 0.220627, 0.251087] に対する argmax 予測は:

解答根拠と履歴

    独立習得基準

    x、h、z、p を参考値と小数 6 桁まで一致させて独立に再現し、argmax '.' をインデックス 0 と特定し、未訓練予測について正直なコメントができる。

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

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

    該当セクション・タイムスタンプ: End-to-end forward pass segment evaluated on a single 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 | オリジナル出所URL ↗

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