Attention Mechanism / Self-Attention

A mechanism that allows a model to dynamically focus on different parts of the input by computing a weighted combination of values based on compatibility of queries and keys.

Method

Attention(Q,K,V) = softmax(QKᵀ / sqrt(d_k))V. Self-attention and cross-attention differ in the origin of their queries, keys and values.

Applications

Core of Transformers, machine translation, image captioning, document summarization, protein structure prediction (AlphaFold attention), time-series forecasting.

Advantages

Captures long-range dependencies; parallelizable; content-based addressing is flexible; highly effective inductive bias for sequences.

Limitations

Quadratic complexity; can attend to spurious correlations; interpretability of attention weights is debated; requires sufficient data to learn meaningful alignments. Attention(Q,K,V) = softmax(QKᵀ / sqrt(d_k))V. Self-attention and cross-attention differ in the origin of their queries, keys and values.

Alternatives

Recurrent attention, linear attention approximations, convolutional attention, state-space models.

Editorial clarification

Attention(Q,K,V) = softmax(QKᵀ / sqrt(d_k))V. Self-attention and cross-attention differ in the origin of their queries, keys and values.

Sources

Educational reference only, not professional advice.

All algorithms