Self-attention

Also: intra-attention

Queries, keys and values are all linear projections of the same sequence, so each position gathers information directly from any other position in one step. Its cost grows with the square of sequence length; a causal mask restricts each token to earlier positions for generation.

Each token attends to every other token; line weight is the attention score

Example

In "The animal didn’t cross the street because it was too tired", self-attention lets "it" put most of its weight on "animal". A 1,000-token input needs a 1,000 × 1,000 score matrix per head.

See it in the lesson: Transformers & Attention Mechanisms →

Related terms

More in Neural Architectures