Scaled dot-product attention is a way of computing attention that builds weights for "where to look and how much" from dot products of queries and keys, and sums the values using those weights. It was proposed by Vaswani et al. in 2017 in the Transformer paper "Attention Is All You Need", and almost all of today's large language models use this computation.
The formula fits on one line (Eq. (1) of the paper).
The symbols mean the following.
- : queries (an matrix). vectors, each representing "what is being looked for".
- : keys (an matrix). Labels describing "what information each position holds".
- : values (an matrix). The content actually retrieved from each position.
- : the length of the query and key vectors. Dividing by is the "scaled" part.
Think of searching for a book in a library: the query is "a note describing what you want", the key is "the book's spine", and the value is "the book's contents". The more a note resembles a spine, the larger the weight, and the more of that book's contents is taken in. The weights are computed with the softmax function, so they sum to 1 for each query.

