AI & automation

What is the attention mechanism?

The attention mechanism is the part of a transformer model that lets each token look at every other token in the input and decide how much each one matters to its meaning, so context such as who it refers to or which order is meant gets resolved.

An everyday example

Take the sentence: "The courier dropped the parcel at reception because it was closed." What was closed? A person knows it was reception, not the parcel. Attention lets the model connect "it" strongly with "reception" and weakly with the other nouns, based on patterns learned from training data.

Each layer of a model runs many attention "heads" side by side. Some seem to track grammar, some follow names across paragraphs, others pick up formatting. Together they build a rich picture of the text.

Why it affects your bill and your results

In its basic form, attention compares every token with every other token, so work grows quickly as the input gets longer. That is a big reason long prompts cost more and respond more slowly, and why providers price by tokens. Engineering tricks have pushed context windows into hundreds of thousands of tokens, but models can still pay less attention to material buried in the middle of a very long input. Practical advice that follows: send the model the relevant passages rather than an entire document archive, and put key instructions where they are easy to find.

Attention outside language

The same idea powers image, audio and video models, where the pieces being compared are patches of a picture or slices of sound.

Questions, answered

No. It is a mathematical weighting of relationships learned from data, which often produces understanding-like behavior without human comprehension.

Attention in which a sequence looks at itself, each token weighing the others in the same input, which is the kind transformers rely on.

By the Stegnor team · Updated