AI GLOSSARY · AI CONCEPTS

Attention mechanism

Markdown version

Definition

An attention mechanism is a technique that lets a neural network weigh how relevant each part of its input is when producing each part of its output. Transformers are built from attention layers.

Also called: attention, attention in transformers, attention mechanism in deep learning, attention layer, attention mechanisms.

In plain language

When you read a long email to answer one question in it, your eyes jump to the few sentences that matter and skim the rest. An attention mechanism gives an AI model a similar ability. For each word it is working on, the model scores the positions permitted by its attention mask or pattern for relevance and leans on the high scorers. That is how a model can tell what 'it' refers to in a sentence. It is not human attention and it does not mean the model understands. It also adds work: IBM notes that later attention variants were developed to reduce computational demands.

Technical definition

In self-attention, queries, keys and values are projected from one sequence. In cross-attention, queries can come from a decoder while keys and values come from encoder outputs; masks restrict the permitted positions. According to IBM, alignment scores between queries and keys are turned into weights by a softmax function, and the weights decide how much each value contributes to the output. Self-attention applies this within a single sequence, and multi-head self-attention runs several such computations side by side. The paper Attention Is All You Need proposed the Transformer, an architecture that removes recurrence and convolution but also includes position-wise feed-forward layers and other components. Transformers must encode positional information, as IBM notes.

Worked examples in this catalogue

Catalogue examples point at a skill, guide or coding tool listed on this site, with what to run and what you see. An example marked illustrative describes the item from its own documentation; it was not executed for this page. Platform Scores are our assessment under a published method, not a safety guarantee.

  1. Guide · Illustrative, not executed

    What Is an LLM? The Facts Agent Users Need

    What you see
    The guide contrasts a Transformer decoder's autoregressive generation with BERT's masked pretraining, and distinguishes runtime context from learned parameters.
    Why it exercises the concept
    The model combines learned parameter knowledge with supplied context. Curating the retained context changes what evidence is directly available for this request.
  2. Skill by Skill Almanac · Illustrative, not executed

    context-window-packer 56/100 · Provisional, not yet measuredScored · Method v0.2 · How we score

    What to try
    Give the skill a set of files and a token budget.
    What you see
    A choice of which files fit one prompt's token budget, with a record of what was kept, shrunk or dropped, and why.
    Why it exercises the concept
    Retained input and the model's masks or attention pattern determine which positions can interact, so choosing what goes in is a direct way to shape what the model works from.
  3. Coding tool · Illustrative, not executed

    Claude Code

    What to try
    /context
    What you see
    Claude Code's /context command shows what is currently filling the session's context.
    Why it exercises the concept
    It reports context usage, not actual attention weights or guaranteed future recall; review stale material before the next task.

How it shows up when you use agents

Attention operates inside documented attention-based models. An agent application selects, retains or summarizes instructions, files and tool results for its context window. Permitted attention connections depend on the selected model and masks; do not infer every coding product's hidden architecture or that all earlier material remains directly available.

That has practical effects. A long session carries a lot of older material, and Anthropic's documentation, as summarised in our LLM guide, notes that accuracy and recall degrade as the token count grows. Relevant material buried among noise can be weighted poorly, so the model may miss a rule you gave early on. Cost depends on the tokens actually retained and accounted for, cache behavior, and the provider or plan; prompt length alone is not an invoice.

What breaks when this is misunderstood: people paste whole repositories into a prompt and expect the model to find the one relevant file, or they assume an instruction stays equally strong however much text follows it. The safer habit is to curate. Use /context in Claude Code to see what is filling the window, trim stale tool output, and use context-window-packer when you must fit files under a budget. Next time an agent ignores an instruction, check how much else was in the context before rewriting the prompt.

Common confusions

  • Attention versus transformer. Attention is a technique. The transformer is an architecture built from attention layers, according to the paper that introduced it.
  • Attention versus understanding. According to IBM, attention weights reflect the relative importance of each part of an input sequence.
  • Attention versus memory. Attention works within the prompt the model is given for this request. It does not store anything between requests.
  • Myth. A bigger window means the model uses all of it equally well. Anthropic documentation, as summarised in our guide, notes recall can degrade as input grows.
Show all 15 related terms

Terms that mention Attention mechanism

8 terms mention this one

More in AI concepts

Next steps

  1. What Is an LLM? The Facts Agent Users Need The long-form guide.
  2. context-window-packer A skill that exercises it.
  3. Transformer Related term.
  4. Token Related term.
  5. All glossary terms A to Z and by family.

Sources

Definitions are written by Skill Almanac from these sources and were checked against them on 2026-11-25. Wikipedia is never the only source.

Review record

Last verified

Drafted by Claude (original draft) and OpenAI Codex (targeted revisions); sources and example targets checked by Independent automated source review (OpenAI Codex); not human peer review on 2026-11-25. Last verified .

Change log (5)
  • : Independent automated factual/example review completed. Cached US query estimate aligned to receipt; no traffic promise. Final technical gate recorded separately; publication disabled.
  • : Bounded batch-13 source and illustration repairs; independent affected recheck pending, publication disabled.
  • : First version.
  • : Verifier pass: applied verifier corrections (unsourced claims dropped or softened, attributions tightened).
  • : Automated review completed; approved for the staged public release. Search indexing is controlled by the release configuration.