Glossary termTechnique

Attention Mechanism

Also known as: Attention, Self-attention

Neural network technique that lets a model weigh the relevance of different parts of its input when producing each part of its output.

An attention mechanism lets a neural network focus selectively. When processing one element, such as a word being translated, the model computes how relevant every other element is and forms a weighted combination of their information. In the widely used scaled dot-product form, each element is represented by three learned vectors: a query, a key and a value. Similarity between a query and each key determines the weights, which are then applied to the values. Self-attention applies this within a single sequence, so every token can draw on every other.

Attention entered mainstream deep learning with a 2014 paper by Dzmitry Bahdanau, Kyunghyun Cho and Yoshua Bengio on neural machine translation. Earlier recurrent translation models squeezed a whole sentence into one fixed-size vector; attention let the decoder look back at all encoder states and align output words with relevant input words. In 2017 the transformer dropped recurrence entirely and built a network from attention alone, using multiple attention heads in parallel so that different heads can track different kinds of relationships.

Attention is the core operation in large language models and many vision and audio systems. Its computational cost grows quadratically with sequence length in the standard form, which has driven research into sparse, linear and hardware-aware variants, such as FlashAttention, that make long inputs practical. Attention weights are sometimes inspected to understand model behavior, but researchers caution that they offer an incomplete explanation of what a model is doing, a topic studied in interpretability research.

Key points

  • Attention computes relevance weights between elements and combines their information accordingly.
  • Queries, keys and values are the three learned representations used in scaled dot-product attention.
  • Bahdanau, Cho and Bengio's 2014 translation work popularized attention in deep learning.
  • Standard self-attention scales quadratically with sequence length, motivating many efficiency variants.

Related entries

Glossary term

Neural network architecture based on self-attention, introduced in 2017, that underlies most large language models and many vision and audio models.

Glossary term

Neural network trained on very large amounts of text to predict the next token, able to generate language and perform many tasks from prompts.

Glossary term

Neural network architecture that processes sequences step by step while carrying a hidden state, giving it a form of memory of earlier inputs.

Glossary term

The maximum amount of input, measured in tokens, that a language model can take into account at once, including the text it is generating.

Person

Canadian computer scientist and deep learning pioneer who founded the Mila institute in Montreal and became a leading voice on AI safety.

Glossary term

Research field that seeks to understand how AI models reach their outputs, by explaining their decisions or reverse-engineering their internal mechanisms.

Glossary term

Field of AI and linguistics concerned with enabling computers to analyze, understand and generate human language in text and speech.

Referenced by

Other entries that discuss or point to Attention Mechanism.