Skip to main content

What is an attention mechanism?

The Harvard Chan AI Glossary

In our classes, we often pause to explain the ideas behind AI and the language used to describe it. These posts grew out of those conversations. They’re for anyone who would like to understand AI better, with no technical background assumed.

An attention mechanism is a calculation that helps an AI system combine relevant pieces of information when interpreting something. Rather than treating every word or image region as equally useful, it gives different pieces different amounts of influence. The name is an analogy: the computer is calculating relationships, not paying attention in the human sense.

Consider the sentence, “The dog chased the ball because it was moving.” To interpret “it,” useful information appears elsewhere in the sentence. An attention mechanism can help the system connect that word with other words, including “ball.” The surrounding text changes how an individual word is represented inside the system.

The computer does this using numbers. Pieces of input, such as words or word fragments, are represented as lists of numbers. The model transforms and compares these representations, calculates relationship scores and uses the scores to combine information. A higher score gives one piece more influence in that particular calculation. Scores can change when the sentence changes.

Self-attention means the system is comparing pieces within the same material, such as words within one passage. Cross-attention means information from one set is compared with another, such as a sentence being translated and the translation being written. These are ways of connecting information, not separate kinds of human-like awareness.

Several attention calculations can operate alongside one another. This is called multi-head attention: different sets of calculations can capture different relationships. The results are combined. Attention is a central part of the transformer, a type of AI design used in many language systems, although attention mechanisms also appear in other designs.

A clinical note makes the importance of relationships concrete: “The patient denies chest pain” and “The patient reports chest pain” share much of their wording but say opposite things. Attention contributes to combining those words in context; it does not guarantee that a model preserves the distinction. Nor would a high attention score on “denies” prove that the final summary handled negation correctly. The summary must be checked against the note. Attention scores describe part of a calculation, not a complete explanation of the answer.

Sources: Bahdanau and colleagues — Neural Machine Translation by Jointly Learning to Align and Translate; Jain and Wallace — Attention Is Not Explanation.

If you would like to find out more about AI and improve your leadership skills, consider the AI in Health Care Certificate of Specialization from the Advanced Learning Academy at Harvard T.H. Chan School of Public Health. You can take an individual course or work toward the full certificate.


AI is a fast-moving field. This explanation reflects our class discussions and related material at the time of writing. Terminology, capabilities and tools may change.

For suggested additions or corrections, please email me at tpanch@hsph.harvard.edu.

Dr. Trishan Panch
Program Director, AI in Health Care
Harvard T.H. Chan School of Public Health — Advanced Learning Academy