A matrix encoding how much each sequence element should attend to every other.
The attention matrix is a core computational structure within attention mechanisms, representing the pairwise relevance scores between all elements in a sequence. For a sequence of length n, the attention matrix is an n × n grid where each entry quantifies how strongly one position should attend to another when producing a representation. These scores come from dot products between query and key vectors, which are learned projections of the input. A softmax normalization is then applied so that each row sums to one, producing a probability distribution over positions. The resulting weights are used to compute a weighted sum of value vectors, yielding context-aware representations that reflect the most relevant parts of the input.
The attention matrix is what lets transformer-based models capture long-range dependencies without the sequential bottlenecks of recurrent architectures. Every position can directly attend to every other position in a single operation, so the model can relate distant tokens (for example, a pronoun and its antecedent several sentences apart) more efficiently than RNNs or LSTMs. In multi-head attention, multiple attention matrices are computed in parallel using different learned projections, which lets the model capture different types of relationships (syntactic, semantic, positional) across the same input at once.
In practice, the attention matrix has become a tool for interpretability as well as performance. Researchers often visualize attention weights to see which input tokens a model focuses on when generating a particular output, giving partial insight into model reasoning. Attention weights are not always reliable proxies for importance, though, and their interpretation requires care. Methods like attention rollout and gradient-weighted attention have been developed to produce more faithful explanations.
The attention matrix scales quadratically with sequence length, since an n-token sequence requires an n × n matrix. This becomes a significant computational and memory bottleneck for long documents. The limitation has motivated a wave of efficient attention variants, including sparse attention, linear attention, and sliding-window approaches, all of which approximate or restructure the full attention matrix to reduce cost while preserving most of its expressive power.
Signals turns a topic into a sourced research record you can inspect and rerun. Your first scan is free, and this one starts with Attention Matrix already loaded, so edit it or scan as is.