by Amit Shekhar · 3 April 2026
Math behind Attention - Q, K, and V
The math behind Attention - Query(Q), Key(K), and Value(V) with a step-by-step numeric example.
Read on Outcome School ↗then come back to lock it in
Before you read, guessWhat is the initial calculation performed in the attention mechanism?
Ten seconds, a guess, then read — a wrong guess still makes the answer stick.
What this article covers
- The Attention Formula
- Setting Up: From Words to Vectors
- Creating Q, K, and V Matrices
- Computing Attention Scores (Q x K^T)
- Scaling the Scores
- Applying Softmax
- Computing the Final Output (Attention Weights x V)
- Putting It All Together
The article lives on outcomeschool.com. Read it there, then come back: the tutor in the margin has read it and will answer questions, and the questions below check what stayed.
