Skip to content
— CH. 1 · COGNITIVE ORIGINS AND EARLY HISTORY —

Attention (machine learning)

~4 min read · Ch. 1 of 6
6 sections
  • 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.

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

  1. 1conferenceA non-local algorithm for image denoisingAntoni Buades — 2005
  2. 2journalA review on the attention mechanism of deep learningZhaoyang Niu et al. — 2021-09-10
  3. 6citationAn Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy et al. — 2021-06-03
  4. 7citationQuantifying Attention Flow in TransformersSamira Abnar et al. — 2020-05-31
  5. 8citationClass-Discriminative Attention Maps for Vision TransformersLennart Brocki et al. — 2024-10-25
  6. 9citationjacobgil/pytorch-grad-camJacob Gildenblat — 2025-07-21
  7. 10citationExplainable Prediction of Medical Codes from Clinical TextJames Mullenbach et al. — 2018-04-16
  8. 11citationNeural Machine Translation by Jointly Learning to Align and TranslateDzmitry Bahdanau et al. — 2016-05-19
  9. 12citationIs Attention Interpretable?Sofia Serrano et al. — 2019-06-09
  10. 13arxivSet Transformer: A Framework for Attention-based Permutation-Invariant Neural NetworksJuho Lee et al. — 2018
  11. 15bookParallel Distributed Processing, Volume 1: Explorations in the Microstructure of Cognition: FoundationsDavid E. Rumelhart et al. — MIT Press — 1987-07-29
  12. 16journalLearning to control fast-weight memories: an alternative to recurrent nets.Jürgen Schmidhuber — 1992
  13. 17conferenceLinear Transformers Are Secretly Fast Weight ProgrammersImanol Schlag et al. — Springer — 2021
  14. 18arxivMassive Exploration of Neural Machine Translation ArchitecturesDenny Britz et al. — 2017-03-21
  15. 19arxivEffective Approaches to Attention-Based Neural Machine TranslationMinh-Thang Luong — 2015-09-20
  16. 23arxivNeural Machine Translation by Jointly Learning to Align and TranslateDzmitry Bahdanau et al. — 2014
  17. 24arxivCBAM: Convolutional Block Attention ModuleSanghyun Woo et al. — 2018-07-18
  18. 25arxivMultimodal Multi-Head Convolutional Attention with Various Kernel Sizes for Medical Image Super-ResolutionMariana-Iuliana Georgescu et al. — 2022-10-12
  19. 26book2018 IEEE/CVF Conference on Computer Vision and Pattern RecognitionJie Hu et al. — 2018
  20. 27book2019 IEEE/CVF International Conference on Computer Vision (ICCV)Xizhou Zhu et al. — 2019
  21. 29journalSome Experiments on the Recognition of Speech, with One and with Two EarsE. Colin Cherry — 1953
  22. 30bookPerception and CommunicationDonald E. Broadbent — Pergamon Press — 1958
  23. 31journalThe control of saccadic eye movementsEileen Kowler — 1995
  24. 32journalThe correlation theory of brain functionChristoph von der Malsburg — 1981
  25. 33journalDynamic connections in neural networksJerome A. Feldman — 1982
  26. 34journalConnectionist learning proceduresGeoffrey E. Hinton — 1989
  27. 35arxivLong Short-Term Memory-Networks for Machine ReadingJianpeng Cheng — 2016
  28. 36arxivA Deep Reinforced Model for Abstractive SummarizationRomain Paulus — 2017
  29. 37conferenceShow, Attend and Tell: Neural Image Caption Generation with Visual AttentionKelvin Xu et al. — 2015
  30. 38conference2015 IEEE Conference on Computer Vision and Pattern Recognition (CVPR)Oriol Vinyals et al. — 2015
  31. 39arxivAttention is All You NeedAshish Vaswani et al. — 2017
  32. 40conferenceBilateral filtering for gray and color imagesCarlo Tomasi — 1998
  33. 41conferenceAttentional Neural Network: Feature Selection Using Cognitive FeedbackQian Wang — 2014
  34. 42conferenceDecomposable Attention Model for Natural Language InferenceAnees Parikh — 2016
  35. 43conferenceA Structured Self-Attentive Sentence EmbeddingZichao Lin — 2017
  36. 44conferenceRelation Networks for Relational ReasoningAdam Santoro — 2017
  37. 45conferenceSet Transformer: A Framework for Attention-based Permutation-Invariant Neural NetworksJuho Lee — 2019
  38. 46conferenceNon-Local Neural NetworksXiaolong Wang — 2018
  39. 47conferenceGraph Attention NetworksPetar Veličković — 2018
  40. 48conferenceReformer: The Efficient TransformerNikita Kitaev — 2020
  41. 49conferenceLinformer: Self-Attention with Linear ComplexitySalah Wang — 2020
  42. 50conferenceRethinking Attention with PerformersKrzysztof Choromanski — 2020
  43. 51conferenceHopfield Networks is All You NeedJohannes Ramsauer — 2021
  44. 52conferenceAn Image is Worth 16×16 Words: Transformers for Image Recognition at ScaleAleksander Dosovitskiy — 2021
  45. 53journalHighly accurate protein structure prediction with AlphaFoldJohn Jumper — 2021
  46. 54conferenceLearning Transferable Visual Models from Natural Language SupervisionAlec Radford — 2021
  47. 55conferenceCCNet: Criss-Cross Attention for Semantic SegmentationXiangyu Huang — 2019
  48. 56conferenceDual Attention Network for Scene SegmentationJing Fu — 2019