PythiloLesson 2 of 8 · progress kept in this browser

Scaled Dot-product Attention

A query scores keys; stable softmax turns scores into weights, then a weighted sum mixes values. Inspect scores, weights and the output vector.

weights = [0.25, 0.75]
values = [[2, 0], [0, 2]]
print([sum(w*v[j] for w,v in zip(weights, values)) for j in range(2)])
Your task

attend(query, keys, values) returns one attention output vector using dot products divided by sqrt(len(query)), followed by stable softmax. keys is nonempty, dimensions match, each value has the same width.