Self-attention: every word can look at every word
Use a real sentence. Each word is a token-position, and each curved line shows one possible attention connection between a query word and a key word.
01 · Select a word and trace its connections
02 · Attention score matrix
How to read it: Pick a word from the left-hand side to choose a query row. Move across that row to see how that word compares with every key token along the top.
Example: If “curious” is the query, its row contains a possible score for “curious” against “The,” “cat,” “watches,” and every other word. Those scores help the model determine which context is useful when representing “curious.”
Why n²? With n tokens, there are n rows × n columns = n² cells. Ten tokens therefore create 100 possible token-pair scores.
The highlighted cells show connections for learning purposes; they are not the real attention weights from a trained model.
The connections show possible comparisons, not learned attention weights from a real model.