Module 8 · after
The same 6 questions you saw before the module. No running the code: predict, then compare with your first score.
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)
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)])
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])])
Your answers are saved with a random id, not your name, so we can see which lessons work. Privacy