Attention lets one token gather relevant information from other tokens. It does this with three learned views of every token: a query describing what the current position seeks, a key describing what another position offers, and a value containing information that can be collected.
The model creates queries, keys, and values by multiplying token representations by three learned projection matrices. These are not hand-written database queries or labels. Training discovers projections that help the overall prediction objective.
A query is compared with every allowed key. A stronger match produces a larger score. Softmax turns the scores into weights that sum to one, and the output is a weighted average of the corresponding value vectors.
In 'the animal did not cross because it was tired', the representation for 'it' can query earlier positions. A key for 'animal' may match strongly, causing its value to contribute useful context. The exact pattern is learned rather than programmed.
Queries and keys decide where to look; values decide what information comes back. Keeping this distinction clear prevents a common misconception that the attention weights themselves are the final output or a complete explanation of model reasoning.
For a toy sequence, print query, key, and value shapes, score matrices, row sums after softmax, and final output shapes. Change one token and observe which scores and outputs move. This turns abstract terminology into traceable operations.