A score function assigns a raw importance value to each input in an attention mechanism. Softmax converts the scores into relative weights, which weight the inputs before they are added into the attention output. section 10.1.2
For inputs x₁,…,xₜ, a feature network first produces hᵢ = F(xᵢ). The score function then evaluates each hᵢ. In the simplest form, scores are computed independently; a contextual score also receives information about the whole sequence, such as the average of its extracted features. section 10.1.2 section 10.2
The attention calculation follows this pipeline:
- Transform each input into a learned feature representation. section 10.1.2
- Use the score function to produce one raw score for every item. section 10.1.2
- Apply softmax across the scores to obtain relative importance weights. section 10.1.2
- Multiply each input by its weight and sum the results into the output. section 10.1.2
Context makes a local scoring decision depend on global information: each item can be judged relative to the other items. In multiheaded attention, related scoring uses queries against keys, with values supplying the returned content; dot, general, and additive scores are common choices. section 10.2 section 10.5 section 12.5.1
Listening in a noisy coffee shop
A listener focuses on a friend’s voice because the surrounding conversations provide context. If the friend is absent, different background sounds may receive higher scores, illustrating why contextual scoring can change attention weights. section 10.2
Figure 10.1 Diagram of how attention mechanisms work. The input sequence xt can be variable in number (i.e., you could have T = 1 items, T = 13, or T = any number you like). A score function assigns a raw importance value to each item t. The softmax function creates relative scores. The output is then the weighted average of the inputs.
Follow the diagram from raw scores through softmax to the weighted-average attention output. section 10.1.2
