20/25
Part 5 of 6 · The worked exampleLearn and do

A worked example: two tokens by hand

Here's all of it on two tokens, small enough to check by hand.

Q = np.array([[1.0, 0.0], [0.0, 1.0]])
K = np.array([[1.0, 0.0], [1.0, 1.0]])
V = np.array([[10.0, 0.0], [0.0, 10.0]])

s = Q @ K.T / np.sqrt(2)
w = softmax(s)
print(s.round(2))
print(w.round(2))
print((w @ V).round(1))
Predict

q1 = [1, 0] dots to 1 with both keys. The values are [10, 0] and [0, 10]. What's q1's output?

Pick one to see what it prints.
Pick an answer above to see the rest