交差エントロピー損失:確率からスカラー驚き度へ
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 クラスのロジット z = [1.0, 0.5, -0.5]、ターゲットインデックス 0 で、softmax 確率と NLL を計算する。
3. この例でのパープレキシティ exp(L) の意味は?
e^1 = 2.7183、e^0.5 = 1.6487、e^-0.5 = 0.6065、合計は 4.9735。パープレキシティはターゲット確率の逆数。
L = -ln(0.255169) = 1.365831 nats。一様分布の 1.386294 をわずかに下回るだけで、未訓練モデルはほぼ偶然レベル。2 つ目の例:p = [0.5465, 0.3315, 0.1220]、NLL = -ln(0.5465) = 0.6041。パープレキシティ = 1/0.255169 ~= 3.92:モデルは実質、4 ではなく約 3.9 個の同程度にあり得る選択肢から選んでいる。
両方の損失を小数 4 桁以上で計算し、一様ベースラインとの比較を述べ、パープレキシティを実効語彙サイズとして解釈できる。
公式ソースリソースと権利証跡
makemore: Character-level language models on names.txt
該当セクション・タイムスタンプ: 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)
The original architecture paper; selected jointly as the theoretical citation while Makemore supplies the stepwise implementation walkthrough.
Strong PyTorch rigor but assumes fluent tensor programming; deferred to the Days 43-60 pretraining blocks rather than the first embedding contact.
Strong visual intuition for network mechanics but covers image classification rather than embedding tables and next-token language modeling; retained as optional supplementary viewing.
A Neural Probabilistic Language Model
該当セクション・タイムスタンプ: 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)
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.