AlgoViz

Attention and the context window

easy 7 min

Self-attention lets a position mix information from other eligible positions.

Where it shows up

The same pattern appears across everyday software.

  • How much attention can “it” give an earlier word?

    At the position for It, the model can use earlier permitted positions. The example isolates two candidate keys to make one attention head’s calculation visible. After masking, assume the two allowed positions have these scaled scores. Softmax assigns weights 0.75 and 0.25. Later positions receive no causal attention here. For scalar values 8 and 4, the head outputs 7. A real head combines vectors, and subsequent heads and layers can change the representation.