6 questions on what this module teaches. Guessing is fine: this is your starting point, not a test. Take the same check again at the end to see what you learned.
1. Predict: one head’s match score between a query and a key. What does this print? import math
q = [1, 2, 0, 1]
k = [2, 1, 1, 2]
score = sum(a * b for a, b in zip(q, k)) / math.sqrt(len(q))
print(score) 3.0 6.0 0.75 1.5
2. Predict: the query only cares about the first number. What blend does this print? import math
def softmax(z):
e = [math.exp(v - max(z)) for v in z]
return [x / sum(e) for x in e]
q = [1.0, 0.0]
keys = [[3.0, 5.0], [3.0, -5.0]]
values = [[4.0, 0.0], [0.0, 8.0]]
w = softmax([sum(a * b for a, b in zip(q, k)) / math.sqrt(2) for k in keys])
print([sum(wt * v[j] for wt, v in zip(w, values)) for j in range(2)]) [1.0, 1.0] [2.0, 4.0] [4.0, 0.0] [4.0, 8.0]
3. Predict: what does this print? def rmsnorm(x):
ms = sum(xi * xi for xi in x) / len(x)
scale = (ms + 1e-5) ** -0.5
return [xi * scale for xi in x]
print([round(v, 3) for v in rmsnorm([0.0, 3.0, 0.0, -3.0])]) [0.0, 0.5, 0.0, -0.5] [0.0, 0.707, 0.0, -0.707] [0.0, 1.414, 0.0, -1.414] [0.0, 1.0, 0.0, -1.0]
4. microgpt is generating a name. It has produced “mar” after the start marker and is now working out the next letter. How many times has it computed the key for the “m” so far? Three times Once Never: keys are only made during training Four times
5. A stack has 3 layers, and each layer’s own rate is −0.5. Every layer is wrapped in a residual connection (x = x + layer(x)). What rate reaches the input? −0.5 −0.125 1 0.125
6. microgpt reads “abba” (start marker at position 0). What can you say about the vectors x for the two b’s, at positions 2 and 3, right after line 111? They are the same, because wpe is only added to the first letter They differ, because wte has a separate row for each copy of a letter They are the same, because both look up the same row of wte They differ, because each adds a different row of wpe
Answer all 6 to see your result Your answers are saved with a random id, not your name, so we can see which lessons work. Privacy