An attention weight is a normalized relevance coefficient that determines how strongly one input contributes to a context vector. Dot products produce attention scores; normalization converts those scores into positive values that sum to 1, making them interpretable as relative importance. section 3.3.1 section 3.7
Figure 3.7 The goal of self-attention is to compute a context vector for each input element that combines information from all other input elements. In this example, we compute the context vector z(2). The importance or contribution of each input element for computing z(2) is determined by the attention weights a21 to a2T. When computing z(2), the attention weights are calculated with respect to input element x(2) and all other inputs.
Use the diagram to trace how the weights for query x(2) determine each input's contribution to context vector z(2). section 3.3.1
The attention-weight computation follows this data flow:
- Compute an attention score for each input relative to a query, using a dot product as a similarity measure. section 3.3.1
- Normalize the scores with softmax so each row sums to 1 and every weight remains positive; scaled dot-product attention divides scores by the square root of the key dimension first. section 3.3.1 section 3.4.1
- Multiply the weights by the corresponding value vectors and sum them to produce the context vector. section 3.4.1
- For all tokens, form scores with matrix multiplication, apply softmax across the last dimension, and multiply the resulting weight matrix by the values. section 3.3.2
Six-token worked example
For query x(2) in “Your journey starts with one step,” the raw scores are [0.9544, 1.4950, 1.4754, 0.8434, 0.7070, 1.0865]. Softmax produces [0.1385, 0.2379, 0.2333, 0.1240, 0.1082, 0.1581], which sum to 1. Multiplying the six input vectors by these weights yields context vector [0.4419, 0.6515, 0.5683]. section 3.3.1 section 3.3.1
In trainable self-attention, the inputs are projected into query, key, and value vectors with Wq, Wk, and Wv. The attention weights are dynamic, context-specific coefficients, unlike the learned weight parameters in those matrices. section 3.4.1 section 3.4.1

