Every token builds queries, keys and values, then gathers information from the other tokens that match its query.
Introduced inJun 2017Attention Is All You Need
Self-attention is the core transformer operation: each position emits a query that is compared against the keys of the other positions, and the resulting weights average their values. It is what lets the model relate any token to any other, at a cost that grows with the square of sequence length. Which is why so many of the surrounding tricks (GQA, sliding windows, sparse and linear attention) exist to tame it.
Share of new models that have included self-attention over time.
Open any of these on hfviewer to find this block in the interactive architecture graph.
Browse all 1181 models with this in the catalog →
hfviewer renders the full architecture of 3,500+ Hugging Face models as interactive graphs. Hover any block to see what it does, with this model’s real numbers.
Browse all model graphs →