Skip to content
Science, DecodedContext Jamming

Equation Inspector

Scaled dot-product attention

Mathematical modelAI / MLMathematics
Attention(Q,K,V)=softmax ⁣(QKTdk)V\mathrm{Attention}(\htmlClass{sjt-Q}{Q},\htmlClass{sjt-K}{K},\htmlClass{sjt-V}{V}) = \htmlClass{sjt-softmax}{\mathrm{softmax}}\!\left(\frac{\htmlClass{sjt-QKT}{Q K^{T}}}{\htmlClass{sjt-sqrt}{\sqrt{d_k}}}\right)\htmlClass{sjt-V2}{V}

Tap a symbol above, or choose one here:

Meaning

One vector per position: "what am I looking for?" Computed as Q = XW_Q from the input.

Its job in this equation

One side of every relevance comparison.

Picture it

A search query typed by each word.

Read it, progressively

1. Gist

Each word looks at every other word, decides how relevant each one is, and takes a relevance-weighted blend of their information.

What it does not establish

Attention weights are not explanations: a high weight does not prove that token was "why" the model answered as it did. The equation omits masks, multiple heads, projections, positional information and the rest of the transformer block.

Play with it

Loading interactive…