40 / 90

Day 40: Learned Embedding Tables and Distributed Representations

Replace sparse one-hot indicators with a learned embedding matrix C. Prove the lookup-row identity, read rows as points in feature space, and predict tensor shapes and parameter counts before any forward pass. Every activity records prediction, observation, review, and recovery.

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

From One-Hot Vectors to Embedding Lookup

Agent-Assisted Engineering Check

Prerequisites

Day 39 tokenization and n-gram statistics; basic matrix multiplication from the mathematics block.

Learning Objective

Derive why an embedding lookup equals a one-hot vector times the embedding matrix, and predict table shapes and parameter counts for real configurations.

Instructions

Required work: use the tiny vocabulary V = {'.', 'a', 'b', 'c'} (indices 0-3) and embedding table C with rows '.'=[0.1,0.3], 'a'=[0.2,-0.1], 'b'=[-0.4,0.5], 'c'=[0.0,0.2], shape (V,d) = (4,2). Show that multiplying one-hot e_2 = [0,0,1,0] by C selects row 2, giving [-0.4, 0.5]. Explain why code uses integer lookup C[i] instead of materializing a V-dimensional one-hot vector. Optional work: state what changes if the same character is embedded by two different tables.

Practice & Prediction Log

1. Compute e_3 * C for the table above and state which row is selected.
2. For the names vocabulary V=27 with d=10, state the shape and parameter count of C.
3. In one sentence, why is C[i] cheaper than building e_i and multiplying?

Independent Mastery Criterion

The learner writes the identity e_i * C = C[i,:], computes both worked lookups correctly, and derives the 270-parameter count for the (27,10) table without prompting.

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: makemore MLP lecture segment: indexing the embedding table C with one-hot vectors

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 (feature vectors and the joint probability model)

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

Distributed Representations: Rows as Learned Points

Independent Mastery Check

Prerequisites

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

Learning Objective

Interpret embedding rows as coordinates in a learned feature space, compute dot products and cosine similarity, and explain why untrained rows carry no semantics.

Instructions

Required work: treat each row of C as a point in R^2. Compute dot(u,v) = sum_i u_i v_i and cos(u,v) = dot(u,v)/(||u||*||v||) for two row pairs. Then explain, in your own words, what training must change for 'similar' characters to end up near each other: the table starts random, so initial distances are meaningless. Optional work: sketch the four points on paper and mark the closest pair.

Practice & Prediction Log

Using rows '.'=[0.1,0.3], 'a'=[0.2,-0.1], 'b'=[-0.4,0.5], 'c'=[0.0,0.2]:
1. Compute dot('.', 'c') and cos('.', 'c').
2. Compute cos('a', 'b').
3. Which pair is closest in this table, and would you trust these similarities before training? Why?

Independent Mastery Criterion

Both cosines computed independently within +-0.01, plus a correct statement that random embeddings encode no semantics until trained.

Authoritative Source Resources & Provenance

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 1 (distributed representation fights the curse of dimensionality)

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.

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: Embedding table inspection segment; 2-D embedding visualization of learned character rows

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.

03 120 min

Context Concatenation and the Parameter Ledger

Agent-Assisted Engineering Check

Prerequisites

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

Learning Objective

Assemble a model input by concatenating per-position embedding rows in context order, predict its dimension, and maintain a complete parameter ledger for the tiny model and a names-scale configuration.

Instructions

Required work: for block_size = 2 and context ('a','b') = indices [1,2], the network input is x = concat(C[1], C[2]) = [0.2, -0.1, -0.4, 0.5], dimension block_size * d = 4. Build the same vector for context ('b','.'). Then write the parameter ledger for the tiny model (hidden size 3) and for a names-scale configuration V=27, d=10, block=3, hidden=100. Optional work: explain why position order in the concatenation cannot be shuffled.

Practice & Prediction Log

1. Write x for context ('b','.').
2. Tiny ledger: C (4x2), W1 (4x3), b1 (3), W2 (3x4), b2 (4) - total parameters?
3. Names ledger: C (27x10), W1 (30x100), b1 (100), W2 (100x27), b2 (27) - total parameters?

Independent Mastery Criterion

Correct concatenated vector with positions in order, plus both ledgers (39 and 6097) derived rather than recalled.

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 building X from context indices and flattening C[X] into the input layer

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 (concatenated feature vectors x = (C(w_{t-n+1}), ..., C(w_{t-1})))

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: Lookup, Shapes, and Parameter Counts

Independent Mastery Check

Prerequisites

Activities 40-01 through 40-03.

Learning Objective

Verify unaided mastery of embedding lookup, distributed geometry, context concatenation, and parameter accounting under declared AI-free conditions.

Instructions

Required work: work closed-book and record derivations in the draft workspace before opening the reference solution or the knowledge check. Do not consult AI assistants or calculators for the derivations themselves (you may verify arithmetic afterwards). Optional work: redo the ledger with hidden size 200 and compare.

Practice & Prediction Log

A new task uses V=8 symbols, d=4, block_size=3, hidden=64.
1. Shape and parameter count of C.
2. Dimension of the concatenated input x.
3. Total parameters for C, W1, b1, W2, b2.
4. One sentence: why does training move embedding rows at all?

Objective Knowledge Check: Embeddings & Lookup Tables

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.

For a vocabulary of V=27 symbols embedded into d=10 dimensions, how many trainable parameters does the embedding table C contain?

2.

Multiplying the one-hot vector e_i by the embedding matrix C produces:

3.

With block_size = 3 and embedding dimension d = 10, what is the dimension of the concatenated context vector x?

Attempt History & Evidence

    Independent Mastery Criterion

    Independent derivation of all four answers: 32 parameters, dimension 12, total 1384, and a correct one-line explanation of gradient-driven row movement.

    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: Embedding table construction and parameter summary segments

    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 (model overview and notation)

    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.