Fill the blank: for a single head, QK^T has shape (T_query, ___).
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
QK^T has shape (T_query, T_key). Each entry is the dot-product similarity between one query token and one key token.
Imagine a spreadsheet where rows are people asking questions and columns are books that might answer them. Every cell holds a score for how well that book matches that question. If five people ask questions and there are twenty books, you get a five by twenty grid. That grid is QK^T. The row count comes from how many askers there are (queries), and the column count comes from how many books exist (keys). In self-attention the askers and the books are the same set, so the grid is square. In cross-attention they are different sets, so the grid is rectangular.
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.
State the shape with the matmul rule, explain self vs cross-attention shape symmetry, connect to O(n^2) memory and FlashAttention, mention causal mask shares the same shape.
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.
Writing d_head as the second dimension. The d_head axis gets contracted by the matmul, what remains is the two sequence lengths.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.