Glossary

What is Self-attention?

In Turkish: Öz dikkat (self-attention) · Topic: Models and training

A type of attention in which each element of a sequence looks at the other elements of the same sequence to update its own representation in context. It is the core building block of Transformer models.

How does it work?

For each token, three vectors are produced: a query, a key and a value. A token's query is compared with all the keys in the sequence, and the resulting scores are turned into weights. The token's new representation is the sum of the values blended with those weights. In this way each token pulls in information from the other tokens it needs to settle its meaning. Because every pair is compared, the cost grows quickly with sequence length, roughly with its square.

Why does it matter?

Self-attention lets a model link distant words in a text directly and run the computation in parallel. This sped up training compared with older recurrent networks and opened the way to very large models. The high price of long-context models also comes from the way self-attention cost grows with sequence length.

Example

In the sentence 'The cat drank the milk because it was hungry', the model looks at the other words while updating the representation of 'it' and will most likely link it to 'cat'.

FAQ

What is the difference between self-attention and the attention mechanism?

The attention mechanism is the general idea and can link two different sequences, such as a target sentence looking at a source sentence in translation. In self-attention a sequence only looks at its own elements.

Why is self-attention computationally expensive?

Every element is compared with every other element, so the cost rises quickly with sequence length. Doubling the context roughly quadruples the workload.

All terms