Scaled dot-product attention

Deep learning · Formula · Appears in 4 lessons

Attention(Q,K,V)=softmax ⁣(QK⊤dk)V\mathrm{Attention}(Q, K, V) = \mathrm{softmax}\!\left(\frac{QK^{\top}}{\sqrt{d_k}}\right) V

Every token proposes a query, every token advertises a key, and the match between them decides whose value gets read. Dividing by the square root of the key dimension keeps the dot products from growing with width and flattening the softmax gradient.

Symbols

QQ
The queries — what each position is looking for.
KK
The keys — what each position offers.
VV
The values — what actually gets mixed and returned.
dkd_k
The key dimension, whose square root rescales the scores.
Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark