Skip to content
Ask Sera Search
Ask SeraAnswers from our guides, research and news Search
Learn
Guides
Research
Sectors
Platforms
News
Tools
About

What is attention in AI?

Attention is the mechanism in a transformer that lets each token weigh every other token in the input when the model computes its output.

In short. Attention is the mechanism in a transformer that lets each token weigh every other token in the input when the model computes its output. For each token, the model scores how well every other token matches it and mixes in their information by those scores. The 2017 paper Attention Is All You Need built the transformer from attention alone. Its cost grows with the square of the input length.

On this page 7 sections

The evidence

  • Confirmed:

    Attention Is All You Need defines an attention function as a mapping from a query and a set of key-value pairs to an output. The output is a weighted sum of the values, and each weight comes from how well the query matches a key.1arXiv, Jun 12, 2017. Section 3.2 of the paper

  • Confirmed:

    The paper gives the cost of a self-attention layer as O(n²·d) for n tokens, so the cost grows with the square of the input length. The layer connects any two positions in a constant number of steps, where a recurrent layer needs n steps.1arXiv, Jun 12, 2017. Table 1 of the paper

  • Confirmed:

    A 2014 paper on machine translation let a model search the source sentence for the parts relevant to each word it predicts. Attention Is All You Need calls this method additive attention.2arXiv, Sep 1, 2014

  • Observed:

    In a 2023 study, language models used relevant information best when it was at the start or end of a long input. Performance dropped when the information was in the middle.3arXiv, Jul 6, 2023. Multi-document question answering and key-value retrieval

Confirmed by the platformObserved in data

Attention decides how much each token of a prompt affects every other token. In AI search, it is how a model relates the question to the retrieved pages in its context window. It is the core of the transformer, the architecture behind current large language models.

#How does attention work?

Attention computes a new representation for each token as a weighted mix of the tokens around it. Attention Is All You Need describes an attention function as a mapping from a query and a set of key-value pairs to an output. The output is a weighted sum of the values. Each weight comes from how well the query matches the corresponding key.1

The paper's version is called scaled dot-product attention. The model multiplies the query by every key, divides the results by the square root of the key size, and applies a softmax function to turn the scores into weights.1

The paper shows an example from its own model. When the model processes the word "making", several attention heads give weight to the distant words "more difficult", which complete the phrase "making ... more difficult".1

In self-attention, the queries, keys and values all come from the same text. In a model that generates text, a mask lets each token attend only to the tokens before it.1 What is a transformer in AI? covers multi-head attention and the rest of the architecture.

#Where did the attention mechanism come from?

Attention came from machine translation. Neural Machine Translation by Jointly Learning to Align and Translate, submitted in September 2014, said that a fixed-length vector for the whole source sentence limited translation quality. It let the model search for the parts of the source sentence that are relevant to each word it predicts.2 Attention Is All You Need calls this method additive attention.1

Those earlier models used attention on top of recurrent networks, which read a text one token at a time. The 2017 paper removed the recurrence and built the transformer from attention alone. What did the Attention Is All You Need paper introduce? covers the paper and the models that followed it.

#What does attention cost?

Self-attention compares every token with every other token, so its cost grows with the square of the input length. The paper gives the complexity of a self-attention layer as O(n²·d), where n is the number of tokens and d is the size of each token's vector. In exchange, the layer connects any two positions in a constant number of steps. A recurrent layer needs n steps.1

A prompt of 100,000 tokens has four times as many token pairs as a prompt of 50,000 tokens. The paper suggests restricting attention to a neighborhood of nearby tokens to improve performance on very long sequences.1

#How does attention affect AI search answers?

An AI search answer comes from a model that attends across the question and every retrieved passage at once. Attention lets any passage affect any word of the answer. It does not make the model use every passage equally well. In Lost in the Middle, a 2023 study, models used relevant information best when it was at the start or end of a long input. Performance dropped when the information was in the middle, even for models built for long contexts.3 What is a context window? covers how much of a page reaches the model.

Read next

Used in

Related terms

Questions

What is self-attention?

Self-attention is attention in which the queries, keys and values all come from the same sequence. Each token of a text attends to the other tokens of the same text. Attention Is All You Need also calls it intra-attention.

Why does attention make long inputs expensive?

Self-attention compares every token with every other token, so its cost grows with the square of the input length. Twice as many tokens means about four times as many token pairs. The 2017 paper suggests limiting attention to nearby tokens for very long sequences.

Is attention the same as a transformer?

No. Attention is a mechanism, and the transformer is an architecture built around it. A transformer also has feed-forward layers, embeddings and positional encodings. Earlier translation models used attention together with recurrent networks.

About this page

Researched and reviewed by Promptly Found. Reviewed Dec 1, 2026. Next review due Mar 2027.

Notes

  1. 1
    Attention Is All You NeedarXiv · Jun 12, 2017 · Checked Dec 1, 2026 · Paper
  2. 2
    Neural Machine Translation by Jointly Learning to Align and TranslatearXiv · Sep 1, 2014 · Checked Dec 1, 2026 · Paper
  3. 3
    Lost in the Middle: How Language Models Use Long ContextsarXiv · Jul 6, 2023 · Checked Dec 1, 2026 · Paper
Cite this page
Citation style

Promptly Found. (2026, December 1). What is attention in AI? https://promptlyfound.com/glossary/attention

Revisions 1
First published.