Study the paper
Attention Is All You Need
Lessons, visuals, quizzes, flashcards, and resources—organized in teaching order.
Scaled dot-product attention
Scaled dot-product attention
Scaled dot-product attention
Source equation
Sources
S3.E1
Attention(Q,K,V)=softmax(QKTdk)V\mathrm{Attention}(Q,K,V)=\mathrm{softmax}(\frac{QK^{T}}{\sqrt{d_{k}}})V (1)
\mathrm{Attention}(Q,K,V)=\mathrm{softmax}(\frac{QK^{T}}{\sqrt{d_{k}}})VDeep dive
The product forms query-key scores, division by scales them, softmax normalizes each score row, and multiplication by returns weighted values.
Sources
S3.E1
Attention(Q,K,V)=softmax(QKTdk)V\mathrm{Attention}(Q,K,V)=\mathrm{softmax}(\frac{QK^{T}}{\sqrt{d_{k}}})V (1)
\mathrm{Attention}(Q,K,V)=\mathrm{softmax}(\frac{QK^{T}}{\sqrt{d_{k}}})VImplementation detail
Illustrative scalar case: if the unscaled score is 2 and , the scaled score is 1 before softmax.
- Query matrix · n_q x d_k
- Key matrix · n_k x d_k
- Value matrix · n_k x d_v
- Key-vector dimension