41 / 90

Day 41: The Neural Language Model Forward Pass

Trace a Makemore-style MLP end to end by hand: embedding lookup, context concatenation, the tanh hidden layer, output logits, and a numerically stable softmax. Every activity records prediction, observation, review, and recovery.

Models & Training 480 active minutes (8 hours focused study)
01 120 min

Neural Language Model Pipeline: Indices to Pre-Activations

Agent-Assisted Engineering Check

Prerequisites

Day 40 embedding lookup and context concatenation; Days 34-36 MLP mechanics.

Learning Objective

Walk the full pipeline indices -> C rows -> concatenated x -> hidden pre-activations, and compute the input and pre-activation vectors by hand.

Instructions

Required work: use the Day 40 table C and context ('a','b'), so x = [0.2, -0.1, -0.4, 0.5]. Weights stay fixed today: 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]. Compute each hidden pre-activation pre_j = sum_i x_i * W1[i][j] + b1[j]. Record your predicted values before inspecting the trace. Optional work: predict which single input coordinate has the largest influence on pre_1.

Practice & Prediction Log

1. Compute pre_0, pre_1, pre_2 for the x and W1 above, showing every product.
2. Predict whether any pre-activation is exactly zero.
3. Name the pipeline stages in order from raw symbols to pre.

Independent Mastery Criterion

Hand-computed pre-activations match [0.31, -0.51, 0.01] with each product shown, and the learner narrates the pipeline stages in order without notes.

Authoritative Source Resources & Provenance

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

Author: Andrej Karpathy | Original Source Link ↗

Relevant Section / Range: Segment wiring the MLP forward pass: C[X] -> hidden tanh layer -> output logits

Verified Version & Date: Repository state verified 2026-10-30; lecture published 2022

Selection Rationale:

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.

Source Prerequisites:

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

Safe Fallback (Offline Resilience):

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.

Compared Candidate Sources & Selection Analysis (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

Author: Yoshua Bengio, Rejean Ducharme, Pascal Vincent, Christian Jauvin | Original Source Link ↗

Relevant Section / Range: Section 2 (the mapping g: context feature vectors to next-word probabilities)

Verified Version & Date: JMLR Volume 3 (2003); verified 2026-10-30

Selection Rationale:

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.

Source Prerequisites:

Probability basics and linear algebra

Safe Fallback (Offline Resilience):

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

Compared Candidate Sources & Selection Analysis (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 min

Hidden Layer by Hand: tanh and Why Nonlinearity Matters

Independent Mastery Check

Prerequisites

Complete the previous activity; use the listed recovery link if blocked.

Learning Objective

Apply tanh element-wise, compute the hidden vector exactly, and justify why a nonlinearity is required between the two linear maps.

Instructions

Required work: h = tanh(pre) element-wise. Use tanh(0.31) = 0.300437, tanh(-0.51) = -0.469945, tanh(0.01) = 0.010000 and verify at least one with a calculator or Python math.tanh. Then answer the collapse question: if the activation were the identity instead of tanh, what would the two linear maps reduce to? Optional work: compute tanh(5.0) and tanh(-5.0) to observe saturation.

Practice & Prediction Log

1. Write the hidden vector h.
2. tanh saturates: what is tanh(5.0) to 4 decimals, and what does saturation imply for very large pre-activations?
3. Prove the collapse: with identity activation, h = x*W1 and z = h*W2, write z purely in terms of x.

Independent Mastery Criterion

Correct h to 6 decimals, the saturation observation, and a one-line proof that stacked linear maps collapse to a single linear map.

Authoritative Source Resources & Provenance

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

Author: Andrej Karpathy | Original Source Link ↗

Relevant Section / Range: Hidden layer construction segment: h = tanh(X W1 + b1) with shape annotations

Verified Version & Date: Repository state verified 2026-10-30; lecture published 2022

Selection Rationale:

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.

Source Prerequisites:

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

Safe Fallback (Offline Resilience):

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.

Compared Candidate Sources & Selection Analysis (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

Author: Yoshua Bengio, Rejean Ducharme, Pascal Vincent, Christian Jauvin | Original Source Link ↗

Relevant Section / Range: Sections 2-3 (hidden layer with tanh units and free parameters)

Verified Version & Date: JMLR Volume 3 (2003); verified 2026-10-30

Selection Rationale:

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.

Source Prerequisites:

Probability basics and linear algebra

Safe Fallback (Offline Resilience):

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

Compared Candidate Sources & Selection Analysis (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 min

Logits, Numerically Stable Softmax, and the Output Distribution

Agent-Assisted Engineering Check

Prerequisites

Complete the previous activity; use the listed recovery link if blocked.

Learning Objective

Compute logits z = h*W2 + b2, apply the max-shifted softmax, obtain the next-symbol distribution, and explain the stability trick with a counterexample.

Instructions

Required work: 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]. Compute z = h*W2 + b2 for yesterday's h. Then softmax: subtract m = max(z), exponentiate, normalize. Counterexample: with logits [1000,999,998], naive exp(1000) overflows float64; the shifted version gives [0.665241, 0.244728, 0.090031]. Optional work: prove softmax(z - c) = softmax(z) for any constant c.

Practice & Prediction Log

1. Compute the four logits z.
2. Compute exp(z_j - m) for m = max(z), the normalizing sum, and p.
3. Verify p sums to 1.
4. In one sentence, why does subtracting the max change nothing mathematically?

Independent Mastery Criterion

Correct z and p to 6 decimals, a verified sum-to-one check, and a correct invariance argument for the max shift.

Authoritative Source Resources & Provenance

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

Author: Andrej Karpathy | Original Source Link ↗

Relevant Section / Range: Output layer and loss segment: logits = h W2 + b2, softmax probabilities, cross-entropy loss

Verified Version & Date: Repository state verified 2026-10-30; lecture published 2022

Selection Rationale:

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.

Source Prerequisites:

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

Safe Fallback (Offline Resilience):

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.

Compared Candidate Sources & Selection Analysis (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

Author: Yoshua Bengio, Rejean Ducharme, Pascal Vincent, Christian Jauvin | Original Source Link ↗

Relevant Section / Range: Section 2 (softmax output guarantees positive probabilities summing to one)

Verified Version & Date: JMLR Volume 3 (2003); verified 2026-10-30

Selection Rationale:

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.

Source Prerequisites:

Probability basics and linear algebra

Safe Fallback (Offline Resilience):

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

Compared Candidate Sources & Selection Analysis (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 min

Independent Mastery Check: Full Forward Pass on a Held-Out Context

Independent Mastery Check

Prerequisites

Activities 41-01 through 41-03.

Learning Objective

Reproduce the entire forward pass unaided for a new context ('b','a') and identify the predicted symbol honestly.

Instructions

Required work: closed-book. For context ('b','a') = indices [2,1], compute the full forward pass with the same C, W1, b1, W2, b2 and predict the next symbol before opening the reference. Optional work: state the cross-entropy loss if the true next symbol were 'a' (index 1) - you will need it on Day 42.

Practice & Prediction Log

For context ('b','a'):
1. Concatenated input x.
2. Pre-activations and hidden vector h.
3. Logits z.
4. Probabilities p and the argmax symbol.

Objective Knowledge Check: Forward Pass & Softmax

Answer the following diagnostic questions to verify your understanding. Select your declared assistance condition before submitting.

Declared Assistance Condition

Note: AI-free work is an honest declared condition, not claimed surveillance.

1.

Why does the numerically stable softmax subtract max(z) from every logit before exponentiating?

2.

Two stacked linear layers with no nonlinear activation between them are equivalent to:

3.

Given p = [0.290410, 0.237875, 0.220627, 0.251087] over symbols ['.','a','b','c'], the argmax prediction is:

Attempt History & Evidence

    Independent Mastery Criterion

    Independent reproduction of x, h, z, p matching the reference to 6 decimals, and the argmax '.' identified as index 0 with an honest comment on untrained predictions.

    Authoritative Source Resources & Provenance

    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

    Author: Andrej Karpathy | Original Source Link ↗

    Relevant Section / Range: End-to-end forward pass segment evaluated on a single minibatch

    Verified Version & Date: Repository state verified 2026-10-30; lecture published 2022

    Selection Rationale:

    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.

    Source Prerequisites:

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

    Safe Fallback (Offline Resilience):

    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.

    Compared Candidate Sources & Selection Analysis (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

    Author: Yoshua Bengio, Rejean Ducharme, Pascal Vincent, Christian Jauvin | Original Source Link ↗

    Relevant Section / Range: Sections 1-2 (architecture overview)

    Verified Version & Date: JMLR Volume 3 (2003); verified 2026-10-30

    Selection Rationale:

    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.

    Source Prerequisites:

    Probability basics and linear algebra

    Safe Fallback (Offline Resilience):

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

    Compared Candidate Sources & Selection Analysis (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.