Exercises — Embedding layers and tied weights
We reuse the tiny world from the parent note so nothing new is assumed:
Here rows (one per token) and columns (one per feature). Everything below is built only from indexing a row and dot products (multiply matching entries, add them up) — the two operations the parent note earned.
Figure 1 below shows as a coloured lookup table: the green box marks row 2 ("the"), the row we retrieve in Problem 1.2, so you can see that "embedding = reading one row".

L1 — Recognition
Problem 1.1
The matrix above has shape . State , state , and say in one sentence what a single row of physically represents.
Recall Solution
(the number of tokens in the vocabulary — count the rows). (the embedding dimension — count the columns). A single row is the learned vector that token is always mapped to; e.g. row 0 is the meaning-vector for "cat", and the green-boxed row in Figure 1 is row 2, "the".
Problem 1.2
Without any multiplication, write down , the embedding of the token "the".
Recall Solution
Embedding is retrieval, not multiplication — we just read row 2 (the green-boxed row in Figure 1): No arithmetic happens. That is the whole point of a lookup table.
Problem 1.3
True or false: with weight tying we set (the same matrix, unchanged). Here and are the input and output matrices defined in the "Names we use" box above. If false, correct it.
Recall Solution
False. We set — the transpose. The input matrix is (rows = tokens); to multiply a -length context vector and get logits we need a matrix, which is exactly .
L2 — Application
Problem 2.1
Given context vector , compute the tied logit for token "cat" (ID 0), i.e. (ignore bias).
Recall Solution
Dot product = multiply matching entries, sum: Because points purely along the first axis, the logit just reads off the first coordinate of "cat"'s embedding.
Problem 2.2
With (same as parent Example 2), compute all four logits under weight tying (no bias). You should reproduce the parent's numbers.
Recall Solution
Each (dot with row ):
Logits . "ran" scores highest because its row is most aligned with .
Problem 2.3
Turn those logits into probabilities with softmax: . Report each to 2 decimals.
Recall Solution
Softmax turns raw scores into a probability distribution (positive, sums to 1) by exponentiating then normalising — the exponential is chosen because it is always positive and monotonic, so a bigger logit always means a bigger probability. . Sum . "ran" wins with . (Small rounding differs slightly from the parent's ; the exact softmax values were confirmed by the symbolic check described in the "How to use this page" box.)
L3 — Analysis
Problem 3.1
The tied logit is . Explain geometrically why a token whose embedding points in the same direction as gets a high logit, using the identity .
Recall Solution
The dot product equals (length of ) (length of ) , where is the angle between the two arrows. Holding the lengths fixed, is largest () when — arrows point the same way — and smallest () when they point opposite (). So alignment = high score. The output layer literally asks: "which token embedding points most like my context vector?" Figure 2 below draws the context arrow (gray) and each token arrow in colour so you can see which one it points most like.

Problem 3.2
Take — this is exactly the embedding of "dog" (row 1). Compute all logits. Which token wins, and what does that reveal about tied weights?
Recall Solution
Winner: "cat" (ID 0) with , narrowly beating "dog" itself (). The self-score is just the squared length of "dog". "cat" wins here because its row is nearly parallel to "dog"'s and slightly longer, so alignment × length pushes it above. This shows tied weights make the geometry of embeddings directly control next-token scores — similar tokens (cat/dog rows are close) score similarly.
Problem 3.3
Recall from the "Names we use" box that is the loss (how wrong the prediction is). With tying, the gradient into is a sum: . In plain words, why does a single row of receive two contributions per step?
Recall Solution
The same matrix is used twice in the forward pass: once at the input (row selected when the token appears) and once at the output (every row dotted with to make logits). By the chain rule, a parameter used in two places gets one gradient term per use, and they add. So an embedding learns simultaneously "what this token means when I read it" and "when I should predict it" — richer supervision from one weight.
L4 — Synthesis
Problem 4.1
GPT-2 small has , . Compute (a) parameters in the untied input + output layers, and (b) parameters in the tied version (shared matrix + one output bias of length ). (c) State the saving.
Recall Solution
One matrix of shape has entries. (a) Untied: input , output another . Total . (b) Tied: one shared plus bias . Total . (c) Saving parameters (~50% of the embedding/projection block). This is why tying matters most for large vocabularies — see 4.2.04-Subword-tokenization-BPE-WordPiece for where comes from.
Problem 4.2
A model uses token embedding plus positional encoding: . Using our tiny , suppose . Compute for "cat" at position 0. Does the token part depend on position?
Recall Solution
The token embedding is position-independent — "cat" always contributes . Only the added 4.3.02-Positional-encoding term changes with position. Separation of concerns: what the token is vs. where it sits.
Problem 4.3
Reuse Problem 2.2's logits . The true next token is "ran" (ID 3). Compute the cross-entropy loss (with the loss from the "Names we use" box) using the softmax probabilities.
Recall Solution
From Problem 2.3, (exact softmax). Cross-entropy for the correct class is just the negative log of its probability: Lower is better; a perfect prediction () would give . This links tied embeddings straight to 5.1.03-Cross-entropy-loss.
L5 — Mastery
Problem 5.1
Prove that the untied model with matrices and can represent every function the tied model can, but not vice-versa — and state the one-line reason tying is still preferred in practice.
Recall Solution
Untied ⊇ tied: the tied model is the special case . Any tied model is obtained from the untied model by choosing those specific weights, so the untied family contains every tied model — it is strictly more expressive (it also allows ). Why tie anyway: more expressive ≠ better. Tying (i) roughly halves parameters, cutting memory and overfitting, and (ii) gives each embedding two gradient signals (Problem 3.3), which empirically improves generalisation. Capacity you don't need is capacity that overfits. (Relevant when adapting models cheaply — see 6.2.04-Parameter-efficient-fine-tuning.)
Problem 5.2
Build a toy embedding matrix and the one-hot vector (the selector for token 1, as defined in the "Names we use" box). Show by explicit multiplication that equals row 1 of , confirming "indexing = one-hot matmul". Then verify numerically with .
Recall Solution
Multiply the row vector into , entry by entry down each column: The kills row 0 entirely; the single copies row 1 straight through. Numeric check with : which is exactly row 1 . This is why we never build the one-hot in code — it computes a row we could just read.
Problem 5.3
Under tying, the self-logit of a token equals the squared length of its embedding: when . Verify this for "ran" (row 3) and explain what it means for a model asked to "predict the token it just saw".
Recall Solution
, so Set : the logit for "ran" is , a token's alignment with itself (, ), the maximum possible cosine. So a context that "looks like" a token strongly prefers predicting that token — the geometric backbone of tied language models, and exactly the mechanism 4.4.03-Self-attention-mechanism exploits when copying context.
Recall Explain it back (self-test)
Embedding = retrieval ::: pick row of ; no multiply needed. Tied output logit for token ::: — alignment of context with token 's embedding. Why transpose, not equal ::: input is (select a row); output needs to turn a length- context into logits, which is . Two gradients per row ::: is used at input and output, so chain-rule terms add. Tied param count ::: (shared matrix + output bias).