Scaled Dot-Product Attention

Trace a query from similarity scores to a weighted value and separate key width from the number of available positions.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. A query compares with every permitted key
  2. Scaling controls the raw score’s magnitude in a simple model

A query compares with every permitted key

For a query \(q\) and key \(k_j\), the score is \(q^\top k_j/\sqrt d\) for key width \(d\) in scaled dot-product attention. Normalize permitted scores with a row softmax and multiply the resulting weights by value vectors. If two allowed scores are equal, their values receive equal weights. A causal mask removes positions the query is not allowed to observe. The values need not equal their keys.

Scaling controls the raw score’s magnitude in a simple model

For independent normalized-scale coordinates, the variance of an unscaled dot product grows on the order of \(d\). The scale makes the initial variance comparable across widths under those assumptions. Dense attention still creates one score per allowed query–key pair. Stable softmax avoids overflow. Efficient transformers reorganize computation and memory for large contexts.[1][2]

References

  1. Ashish Vaswani et al., Attention Is All You Need ↩
  2. Ian Goodfellow, Yoshua Bengio and Aaron Courville, Deep Learning ↩