Attention (machine learning)
In the 1950s, researchers studied how humans focus on specific sounds while ignoring background noise. This phenomenon became known as the cocktail party effect. Scientists developed filter models to explain how attention selects relevant information from a chaotic environment. By the 1980s, engineers created sigma-pi units and higher-order neural networks that mimicked these biological processes. Fast weight controllers emerged in the early 1990s to establish dynamic links between neurons. These systems anticipated the key-value mechanisms found in modern machine learning. The bilateral filter arrived in image processing during 1998 to propagate relevance across elements using pairwise affinity matrices. Non-local means extended this filtering approach in 2005 by applying Gaussian similarity kernels as fixed attention-like weights. A major shift occurred in 2014 when seq2seq models combined recurrent neural networks with attention mechanisms. This integration allowed translation systems to handle long sentences more effectively than previous designs.
A research paper titled Attention is All You Need appeared in 2017 to introduce the Transformer architecture. This model formalized scaled dot-product self-attention to replace slower sequential recurrent neural networks. Self-attention enabled each element in an input sequence to attend directly to all other elements. This design choice removed the bottleneck of serial processing inherent in earlier RNN systems. Parallel computation became possible because every token could interact with every other token simultaneously. Global dependencies within a sentence were captured without attenuation over distance. Relation networks and set Transformers applied these principles to unordered sets for relational reasoning. Graph attention networks brought the mechanism to graph-structured data in 2018. Efficient Transformers like Reformer, Linformer, and Performer followed between 2019 and 2020 to scale approximations for long sequences. Vision transformers achieved competitive results in image classification during 2019. These architectures formed the foundation for models such as BERT, T5, and generative pre-trained transformers.
Standard scaled dot-product attention defines its operation using query, key, and value matrices denoted Q, K, and V. The softmax function applies independently to every row of the resulting argument matrix. Value vectors are weighted by weights derived from this softmax operation. Multi-head attention computes several heads where each head uses standard QKV attention. Parameter matrices W_Q, W_K, and W_V transform inputs before the dot product calculation. Bahdanau-style attention refers to additive attention which utilizes learnable weight matrices. Luong-style attention is known as multiplicative attention involving a single learnable weight matrix. Masked attention introduces a strictly upper triangular matrix with zeros on and below the diagonal. This mask ensures that output rows remain independent of future input rows during autoregressive decoding. Spatial attention operates along one dimension while channel attention operates along another within convolutional networks. Factorized positional attention adds specific handling for sequence order information. These variants recombine encoder-side inputs to redistribute effects to each target output through correlation-style matrices.
The size of an attention matrix grows proportional to the square of the number of input tokens. Calculating this matrix requires significant GPU memory when processing long sequences. Flash Attention emerged as an implementation to reduce these memory needs without sacrificing accuracy. It achieves efficiency by partitioning computation into smaller blocks fitting into faster on-chip GPU memory. This approach lowers storage requirements for large intermediate matrices. FlexAttention represents another kernel developed by Meta allowing users to modify scores prior to softmax application. Dynamic selection of optimal algorithms occurs based on current data constraints. Partitioning allows the system to avoid storing massive matrices in standard memory pools. The result is increased computational speed alongside reduced hardware demands. These strategies enable training on datasets containing millions of tokens rather than just hundreds.
Natural language processing tasks benefit from improved context understanding provided by attention mechanisms. Question answering and summarization systems rely heavily on these weighted alignments between words. Computer vision models use visual attention to focus on relevant regions within images. Object detection and image captioning performance improve when models can ignore background noise. AlphaFold applied transformers to protein folding problems across scientific domains. CLIP utilized vision-language pretraining to connect text descriptions with image content. Dense segmentation models like CCNet and DANet adopted attention-based approaches for pixel-level classification. Speech recognition systems also integrate attention to handle variable length audio inputs. The mechanism allows models to select specific features while ignoring irrelevant data points. This selective focus drives state-of-the-art results across diverse technical fields.
Visualizing attention scores as heat maps became a routine way to inspect decision-making processes in vision transformers. These visualizations are called saliency maps or attention maps depending on the context. Deeper layers tend to show more semantically meaningful patterns compared to earlier stages. Attention rollout combines scores across all layers using a recursive algorithm that computes dot products. Class-discriminative attention maps combine gradients with respect to the class token for supervised tasks. GradCAM back-propagates gradients to outputs of the final attention layer to highlight important regions. Higher attention scores do not always correlate with greater impact on model performance according to some studies. Debate exists regarding whether attention scores serve as valid explanations for internal decisions. Some pioneering papers analyzed these scores as direct explanations while others found limitations in their reliability. Researchers continue to refine methods for understanding how deep learning systems arrive at conclusions.
Up Next
Continue Browsing
Common questions
When did researchers first study how humans focus on specific sounds while ignoring background noise?
Researchers studied this phenomenon in the 1950s. This observation became known as the cocktail party effect.
What year did the Attention is All You Need paper introduce the Transformer architecture?
The research paper titled Attention is All You Need appeared in 2017 to introduce the Transformer architecture. This model formalized scaled dot-product self-attention to replace slower sequential recurrent neural networks.
How does Flash Attention reduce memory needs for large attention matrices?
Flash Attention emerged as an implementation to reduce these memory needs without sacrificing accuracy. It achieves efficiency by partitioning computation into smaller blocks fitting into faster on-chip GPU memory.
Which year did Graph attention networks bring the mechanism to graph-structured data?
Graph attention networks brought the mechanism to graph-structured data in 2018. These systems applied the core principles of attention to unordered sets and relational reasoning tasks.
Why do higher attention scores not always correlate with greater impact on model performance?
Higher attention scores do not always correlate with greater impact on model performance according to some studies. Debate exists regarding whether attention scores serve as valid explanations for internal decisions.
All sources
55 references cited across the entry
- 1conferenceA non-local algorithm for image denoisingAntoni Buades — 2005
- 2journalA review on the attention mechanism of deep learningZhaoyang Niu et al. — 2021-09-10
- 3journalAttention mechanism in neural networks: where it comes and where it goesDerya Soydaner — August 2022
- 4webFlash Attention: Revolutionizing Transformer EfficiencyAayush Mittal — 2024-07-17
- 6citationAn Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy et al. — 2021-06-03
- 7citationQuantifying Attention Flow in TransformersSamira Abnar et al. — 2020-05-31
- 8citationClass-Discriminative Attention Maps for Vision TransformersLennart Brocki et al. — 2024-10-25
- 9citationjacobgil/pytorch-grad-camJacob Gildenblat — 2025-07-21
- 10citationExplainable Prediction of Medical Codes from Clinical TextJames Mullenbach et al. — 2018-04-16
- 11citationNeural Machine Translation by Jointly Learning to Align and TranslateDzmitry Bahdanau et al. — 2016-05-19
- 12citationIs Attention Interpretable?Sofia Serrano et al. — 2019-06-09
- 13arxivSet Transformer: A Framework for Attention-based Permutation-Invariant Neural NetworksJuho Lee et al. — 2018
- 15bookParallel Distributed Processing, Volume 1: Explorations in the Microstructure of Cognition: FoundationsDavid E. Rumelhart et al. — MIT Press — 1987-07-29
- 16journalLearning to control fast-weight memories: an alternative to recurrent nets.Jürgen Schmidhuber — 1992
- 17conferenceLinear Transformers Are Secretly Fast Weight ProgrammersImanol Schlag et al. — Springer — 2021
- 18arxivMassive Exploration of Neural Machine Translation ArchitecturesDenny Britz et al. — 2017-03-21
- 19arxivEffective Approaches to Attention-Based Neural Machine TranslationMinh-Thang Luong — 2015-09-20
- 20av mediaCS 152 NN—27: Attention: Keys, Queries, & Values2021
- 21av mediaNYU Deep Learning course, Spring 20202021
- 23arxivNeural Machine Translation by Jointly Learning to Align and TranslateDzmitry Bahdanau et al. — 2014
- 24arxivCBAM: Convolutional Block Attention ModuleSanghyun Woo et al. — 2018-07-18
- 25arxivMultimodal Multi-Head Convolutional Attention with Various Kernel Sizes for Medical Image Super-ResolutionMariana-Iuliana Georgescu et al. — 2022-10-12
- 26book2018 IEEE/CVF Conference on Computer Vision and Pattern RecognitionJie Hu et al. — 2018
- 27book2019 IEEE/CVF International Conference on Computer Vision (ICCV)Xizhou Zhu et al. — 2019
- 28webLearning Positional Attention for Sequential RecommendationFan Luo et al. — 3 July 2024
- 29journalSome Experiments on the Recognition of Speech, with One and with Two EarsE. Colin Cherry — 1953
- 30bookPerception and CommunicationDonald E. Broadbent — Pergamon Press — 1958
- 31journalThe control of saccadic eye movementsEileen Kowler — 1995
- 32journalThe correlation theory of brain functionChristoph von der Malsburg — 1981
- 33journalDynamic connections in neural networksJerome A. Feldman — 1982
- 34journalConnectionist learning proceduresGeoffrey E. Hinton — 1989
- 35arxivLong Short-Term Memory-Networks for Machine ReadingJianpeng Cheng — 2016
- 36arxivA Deep Reinforced Model for Abstractive SummarizationRomain Paulus — 2017
- 37conferenceShow, Attend and Tell: Neural Image Caption Generation with Visual AttentionKelvin Xu et al. — 2015
- 38conference2015 IEEE Conference on Computer Vision and Pattern Recognition (CVPR)Oriol Vinyals et al. — 2015
- 39arxivAttention is All You NeedAshish Vaswani et al. — 2017
- 40conferenceBilateral filtering for gray and color imagesCarlo Tomasi — 1998
- 41conferenceAttentional Neural Network: Feature Selection Using Cognitive FeedbackQian Wang — 2014
- 42conferenceDecomposable Attention Model for Natural Language InferenceAnees Parikh — 2016
- 43conferenceA Structured Self-Attentive Sentence EmbeddingZichao Lin — 2017
- 44conferenceRelation Networks for Relational ReasoningAdam Santoro — 2017
- 45conferenceSet Transformer: A Framework for Attention-based Permutation-Invariant Neural NetworksJuho Lee — 2019
- 46conferenceNon-Local Neural NetworksXiaolong Wang — 2018
- 47conferenceGraph Attention NetworksPetar Veličković — 2018
- 48conferenceReformer: The Efficient TransformerNikita Kitaev — 2020
- 49conferenceLinformer: Self-Attention with Linear ComplexitySalah Wang — 2020
- 50conferenceRethinking Attention with PerformersKrzysztof Choromanski — 2020
- 51conferenceHopfield Networks is All You NeedJohannes Ramsauer — 2021
- 52conferenceAn Image is Worth 16×16 Words: Transformers for Image Recognition at ScaleAleksander Dosovitskiy — 2021
- 53journalHighly accurate protein structure prediction with AlphaFoldJohn Jumper — 2021
- 54conferenceLearning Transferable Visual Models from Natural Language SupervisionAlec Radford — 2021
- 55conferenceCCNet: Criss-Cross Attention for Semantic SegmentationXiangyu Huang — 2019
- 56conferenceDual Attention Network for Scene SegmentationJing Fu — 2019