Machine Learning & AI
Advanced

Scaled Dot-Product Attention

Lets each token weigh and aggregate information from all others — the heart of Transformers.

Formula

Attn(Q,K,V)=softmax ⁣(QKdk)V\text{Attn}(Q,K,V)=\text{softmax}\!\left(\dfrac{QK^\top}{\sqrt{d_k}}\right)V

Variables

QQueries
KKeys
VValues
d_kKey dimension

Example

Scaling by sqrt(d_k) keeps gradients stable

Did You Know?

The 2017 paper "Attention Is All You Need" introduced this and launched the era of GPT and BERT.

Share this formula