Skip to content

Attention mechanism

Also called: attention mechanisms, self-attention

Published:

Why was attention introduced?

Early neural translation models had the encoder squeeze an entire source sentence into one fixed-length vector. In 2014 Bahdanau, Cho and Bengio argued that this fixed-length vector was a bottleneck for improving performance [1]. In their model the network searched for the relevant parts of the source sentence each time it predicted a target word [1]. On English-to-French translation the approach performed comparably to the best phrase-based system of the time [1].

What is self-attention?

With self-attention, a model weighs the parts of a single input against each other. Google's machine learning crash course frames it as a question asked for every token: how much does each other token in the input affect the interpretation of this one [3]?

The course uses the sentence "The animal didn't cross the street because it was too tired." Self-attention picks up that "it" relates most strongly to "animal", not "street" [3]. A human reader resolves that without thinking; a model reading the sentence has to build the link explicitly.

Where is attention used?

In 2017 Vaswani and colleagues proposed the Transformer, an architecture built solely on attention mechanisms with no recurrence or convolution [2]. It beat the previous best translation results and also carried over to English constituency parsing [2]. Today's large language models use self-attention through this architecture [3].

Frequently asked questions

What is the difference between attention and self-attention?

Classic attention looks at source words in another sequence while producing output. Self-attention relates the tokens of the same input to one another.

Who first proposed attention?

The widely used form in neural translation comes from the 2014 paper by Bahdanau, Cho and Bengio.

Sources

  1. Neural Machine Translation by Jointly Learning to Align and Translate — arXiv
  2. Attention Is All You Need — arXiv
  3. LLMs: What's a large language model? — Google for Developers