Check a row of normalized attention weights
Type the indices of each value in their original order. · 182 words
A query is the current token's search request, a key is the description of a token being considered, and an attention weight tells the model how strongly to copy that token's value. Start with one query and three keys. Their dot-product scores are [2, 1, 0]. Softmax turns these scores into weights: w_i = exp(s_i) / sum_j exp(s_j). Using exp(2) = 7.389, exp(1) = 2.718, and exp(0) = 1 gives a denominator of 11.107, so the normalized row is [0.665, 0.245, 0.090]. The rounded values sum to 1.000.
Check the row in two ways. First, every weight is positive, and the more precise weights sum to one: 0.665240 + 0.244728 + 0.090031 = 1.000000. Second, apply the weights to token values [10, 20, 40]. The attended value is 0.665240(10) + 0.244728(20) + 0.090031(40) = 6.6524 + 4.89456 + 3.60124 = 15.1482. The largest weight belongs to value 10, so the result stays nearest to that value. A proposed row such as [0.50, 0.30, 0.10] is normalized, but you must compare it with the scores to confirm that it is the correct softmax.
Check your recall
What two checks confirm that an attention row is a valid normalized row for scores [2, 1, 0]?
Check your answer
The weights must be nonnegative and sum to one, and recomputing softmax must produce [0.665240, 0.244728, 0.090031]. When applied to values [10, 20, 40], they give 15.1482.
Sources and credits
Original KeyTouch lesson. Background reading · Vaswani et al. · Attention Is All You Need.