Why do Transformers use a dot product, rather than addition, to compute attention scores?
Answer
The dot product is a natural similarity measure: is large exactly when query and key point in the same direction, so it directly expresses “how relevant is this key to my query”. It is also a single fused matrix multiplication (
scores all pairs at once), which is far faster on modern hardware than additive attention’s per-pair MLP. Scaling by
keeps it numerically stable in high dimensions.
(1) Geometric Meaning: : aligned vectors score high, orthogonal vectors score zero, opposed vectors score negative.
(2) Hardware Efficiency: All scores materialize as one GEMM ; additive attention needs an MLP evaluated for every (query, key) pair.
(3) Probabilistic Readout: Softmax over dot-product scores yields interpretable attention weights: a distribution over which keys matter.

Figure 1: Dot product as similarity: aligned vectors score positive, opposed vectors score negative; softmax turns scores into attention weights.
Mathematical Formulation:
Where:
is the attention weight the query assigns to key
; weights sum to 1 over the
keys.
is the dot-product similarity;
scaling prevents softmax saturation for large key dimension
.
Why Not Addition: Adding features component-wise, , says nothing about alignment; two very different pairs can sum to the same vector. To become a usable score, the sum must pass through an extra learnable MLP (
), which is slower per pair and still lacks the dot product’s direct geometric interpretation.

Figure 2: Dot-product scoring = one batched GEMM; additive scoring = a per-pair MLP, richer but much slower at scale.
The One Caveat: For large , raw dot products grow in variance proportional to
, pushing softmax into saturated, gradient-poor regions, which is why the Transformer uses the scaled dot product rather than the plain one.
Leave a Reply