An attention score measures how relevant a source vector is to the target vector currently being processed. In sequence-to-sequence translation, high-scoring source tokens contribute more information to the prediction, helping the model retrieve relevant context without passing it through a long recurrent loop. section 15.3.1
Dot-product attention turns scores into a context representation:
- Compute the dot product between each target vector and each source vector; nearby vectors receive higher scores. section 15.3.1
- Apply softmax across the source positions so the scores for each target sum to 1. section 15.3.1
- Take the weighted sum of source vectors, using the normalized scores as weights. section 15.3.1
- For target and source sequences, organize the results as a matrix whose rows describe one target position’s source relevance. section 15.3.1
Minimal attention calculation
For one target vector, score every source vector, normalize the scores, and combine the sources: scores <- sources |> sapply(\(source) score(target, source)) |> softmax(); combined <- sum(scores * sources).



