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:
- Confirmed:
- Confirmed:
- Observed:
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
LLMs
What did the Attention Is All You Need paper introduce?
The 2017 Google paper Attention Is All You Need introduced the Transformer, the architecture behind ChatGPT, Claude, Gemini and AI search.
LLMs
How do large language models work?
LLMs predict text one token at a time from what fits in their context window. Tokens, context window sizes and the lost-in-the-middle effect.
LLMs
What is a context window?
A context window is the number of tokens a model can read and write in one request. Sizes from Anthropic, OpenAI and Google, and what happens at the limit.
LLMs
What are tokens in AI?
A token is the unit of text a language model reads and writes. OpenAI estimates that 100 tokens are about 75 English words. Counts and limits by provider.
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
- 2
- 3
Cite this page
Promptly Found. (2026, December 1). What is attention in AI? https://promptlyfound.com/glossary/attention
Revisions 1
- First published.