What does the dot product q . k actually measure inside an attention layer?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
q dot k is the unnormalized affinity score between a query and a key, combining direction (cosine of the angle) with vector magnitude.
Picture two people at a job fair pointing flashlights at each other. The query is your flashlight, the key is theirs. When you both shine straight at each other, the beams overlap a lot, strong match. When you face perpendicular directions, the beams barely cross, weak match.When you face away, the beams point apart, negative match. The dot product is just a number that says how much the two beams overlap. The model later turns that overlap into a probability and uses it to decide how much of the key's payload to pay attention to.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Define the dot product geometrically, name the three alignment regimes, explain why magnitude also matters, motivate the sqrt(d_k) scaling via variance, and connect to softmax turning scores into weights.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Conflating the raw dot product with cosine similarity. They share direction information, but the dot product also scales with vector magnitudes, that magnitude effect matters.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.