Understanding Transformers through the Lens of Pavlovian Conditioning
Mu Qiao · 2025
Read Understanding Transformers through the Lens of Pavlovian Conditioning by Mu Qiao (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2508-08289.txt.
Introduction
Mu Qiao, writing alone, links two fields in this 2025 paper. The paper argues that the attention step in some transformer models works much like classic learning in animals. Old theories of how animals learn from cues, built over a hundred years, are set beside the math of these models.
Qiao shows the update rules match term by term for several model types. That match turns known animal effects into testable claims about the models. One effect, where a strong cue blocks a weaker one, is worked out exactly and checked in tests. The author also finds two ranges for how much a state can hold, and argues that total state size matters more than head count.
Catalog record
| CREATOR | Mu Qiao |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 52 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2508-08289
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
Understanding Transformers through the Lens of Pavlovian Conditioning Mu Qiao Abstract Transformer architectures have revolutionized artificial intelligence (AI) through their attention mechanisms, yet the computational principles underlying their success remain opaque. We present a novel theoretical framework that reinterprets the core computation of attention as Pavlovian conditioning. Our model finds a direct mathematical analogue in linear attention, which simplifies the analysis of the underlying associative process. We demonstrate that attention’s queries, keys, and values can be mapped to the three elements of classical conditioning: test stimuli that probe associations, conditional stimuli (CS) that serve as retrieval cues, and unconditional stimuli (US) that contain response information. Through this lens, we suggest that each attention operation constructs a transient associative memory via a Hebbian rule, where CS-US pairs form dynamic associations that test stimuli can later retrieve. Our framework yields several theoretical insights grounded in this linearized model: (1) a capacity theorem showing that attention heads can store O( d k \sqrt{d_{k}} ) associations before interference degrades retrieval; (2) an error propagation analysis revealing fundamental architectural trade-offs of balancing model depth, width, and head redundancy to maintain reliability; and (3) an understanding of how biologically plausible learning rules could enhance transformer architectures. By establishing this deep connection, we suggest that the success of modern AI may stem not from architectural novelty alone, but from implementing computational principles that biology optimized over millions of years of evolution. 1 Introduction The transformer architecture ( vaswaniAttentionAllYou2017 ) has revolutionized artificial intelligence (AI), achieving unprecedented performance in language modeling, computer vision, and beyond. At the heart of this revolution lies the attention mechanism, a deceptively simple operation that computes weighted averages of values based on query-key similarities. Yet despite transformers’ ubiquity, we lack a satisfying explanation for a fundamental question: Why does this particular computation work so well? The standard mathematical description of attention as is operationally clear but intellectually unsatisfying. It tells us what attention computes but not why this computation captures something essential about intelligence. Current interpretability work ( elhageetal.MathematicalFrameworkTransformer2021 ; olssonetal.ContextLearningInduction2022 ) has made progress identifying specific computational patterns, but these descriptive accounts still leave the core mystery unresolved. We propose a fundamental reinterpretation: the core operation of transformer attention can be understood as a form of Pavlovian conditioning, one of the most basic and universal learning mechanisms in nature. Drawing from classical conditioning theory ( pavlov1927ConditionedReflexesInvestigation2010 ) , we propose a mapping where attention’s three components correspond to conditioning elements: • Values (V) → Unconditional stimuli (US): Information that directly encodes responses • Keys (K) → Conditional stimuli (CS): Contextual patterns that become associated with US • Queries (Q) → Test stimuli: Patterns that probe learned associations for retrieval This decomposition illuminates attention’s fundamental operation as a process of dynamic association. During each forward pass, key (CS)-value (US) pairs form associations via a Hebbian rule ( hebbOrganizationBehaviorNeuropsychological1949 ; gerstnerMathematicalFormulationsHebbian2002 ) , which queries (test stimuli) then probe through similarity matching. This is not only an analogy; we demonstrate that our conditioning framework is mathematically equivalent to linear attention, a simplified yet powerful variant of the standard mechanism. This provides a tractable foundation for our theoretical analysis. Beyond technical contributions, this work suggests a profound principle: the convergence between certain AI architectures and neuroscience may not be coincidental. By implementing conditioning principles, these models may tap into computational solutions that biology has optimized through evolution. This perspective not only helps explain current success but also points toward principled architectural improvements inspired by neuroscience. 2 Background and Related Work 2.1 Transformer Attention Mechanisms Standard transformer attention ( vaswaniAttentionAllYou2017 ) operates on an input sequence \mathbf{X}\in\mathbb{R}^{n\times m} containing n tokens, each represented by an m -dimensional vector. The attention mechanism projects this input through learned weight matrices to produce queries, keys, and values: \mathbf{Q}=\mathbf{X}\mathbf{W}_{Q},\quad\mathbf{K}=\mathbf{X}\mathbf{W}_{K},\quad\mathbf{V}=\mathbf{X}\mathbf{W}_{V} (1) where \mathbf{W}_{Q},\mathbf{W}_{K},\mathbf{W}_{V}\in\mathbb{R}^{m\times d} project inputs into a d -dimensional latent space. The attention output is computed as: \text{Attention}(\mathbf{Q},\mathbf{K},\mathbf{V})=\softmax\left(\frac{\mathbf{Q}\mathbf{K}^{\top}}{\sqrt{d}}\right)\mathbf{V} (2) which is then transformed through the output projection \mathbf{W}_{O} . The scaling factor \sqrt{d} prevents gradient instability but can be absorbed into the weight matrices \mathbf{W}_{Q} and \mathbf{W}_{K} ( elhageetal.MathematicalFrameworkTransformer2021 ) . Recent work ( elhageetal.MathematicalFrameworkTransformer2021 ; olssonetal.ContextLearningInduction2022 ) has made progress in mechanistic interpretability by analyzing specific computational patterns. These studies identify "circuits" as functional subgraphs within transformers, often focusing on the composition matrices \mathbf{W}_{Q}\mathbf{W}_{K}^{\top} (determining attention patterns) and \mathbf{W}_{V}\mathbf{W}_{O} (determining information flow). However, these approaches primarily provide descriptive accounts of what transformers compute rather than explaining why these computations are effective. 2.2 Linear Transformer Attention The quadratic complexity of standard attention poses computational challenges for long sequences. Linear attention methods ( tsaiTransformerDissectionUnified2019 ; katharopoulosTransformersAreRNNs2020 ; choromanskiRethinkingAttentionPerformers2020 ) address this by replacing the softmax with decomposable kernel functions, reducing complexity from O(n^{2}) to O(n) . The key insight is to approximate the softmax-weighted sum with a kernelized outer-product formulation. A common approach involves a non-linear kernel function \phi : \text{LinearAttention}(\mathbf{Q},\mathbf{K},\mathbf{V})=\frac{\phi(\mathbf{Q})(\phi(\mathbf{K})^{\top}\mathbf{V})}{\phi(\mathbf{Q})\phi(\mathbf{K})^{\top}\mathbf{1}} (3) where \mathbf{1} is a vector of ones and the \mathbf{Q}\mathbf{K}^{\top} matrix is never explicitly formed ( katharopoulosTransformersAreRNNs2020 ; choromanskiRethinkingAttentionPerformers2020 ) . While early methods included a normalization factor, later work demonstrated that this can lead to instability and that applying normalization to the entire output is more robust ( qinDevilLinearTransformer2022 ) : \text{NormAttention}(\mathbf{Q},\mathbf{K},\mathbf{V})=\text{Norm}\left(\phi(\mathbf{Q})(\phi(\mathbf{K})^{\top}\mathbf{V})\right) (4) where the normalization can be LayerNorm ( baLayerNormalization2016 ) or RMSNorm ( zhangRootMeanSquare2019 ) . This shifts focus to understanding the core operation \phi(\mathbf{Q})(\phi(\mathbf{K})^{\top}\mathbf{V}) . For a specific token \mathbf{x}_{i}\in\mathbb{R}^{1\times m} with corresponding query, key, and value: \mathbf{q}_{i}=\mathbf{x}_{i}\mathbf{W}_{Q},\quad\mathbf{k}_{i}=\mathbf{x}_{i}\mathbf{W}_{K},\quad\mathbf{v}_{i}=\mathbf{x}_{i}\mathbf{W}_{V} (5) the above norm attention output \mathbf{o}_{i} becomes: \mathbf{o}_{i}=\text{Norm}(\phi(\mathbf{q}_{i})\sum_{j=1}^{i}\phi(\mathbf{k}_{j})^{\top}\mathbf{v}_{j}) (6) This can be rewritten as: \mathbf{o}_{i}=\text{Norm}(\phi(\mathbf{q}_{i})\mathbf{S}_{i}) (7) where \mathbf{S}_{i}=\sum_{j=1}^{i}\phi(\mathbf{k}_{j})^{\top}\mathbf{v}_{j} . This formulation naturally implements causal masking (only attending to past information) and enables efficient iterative updates ( katharopoulosTransformersAreRNNs2020 ; qinDevilLinearTransformer2022 ) .: \displaystyle\mathbf{S}_{i} \displaystyle=\mathbf{S}_{i-1}+\phi(\mathbf{k}_{i})^{\top}\mathbf{v}_{i} (8) As we will show, the linear formulation provides a direct mathematical realization of a classical conditioning circuit, making it an ideal starting point for our theoretical investigation. 2.3 Classical Conditioning and Neurobiology Pavlovian conditioning, or classical conditioning ( pavlov1927ConditionedReflexesInvestigation2010 ) represents one of the most fundamental learning mechanisms in biology, where organisms learn to associate neutral stimuli with meaningful outcomes through experience. In classical conditioning experiments, an unconditional stimulus (US) naturally triggers a response (e.g. smell of food causing salivation) . When paired with the US, an initially neutral stimulus (e.g. sound from a bell), called the conditional stimulus (CS), emerges to elicit a similar response (e.g. salivation). Importantly, conditioning exhibits stimulus generalization ( ghirlandaIntensityGeneralizationPhysiology2002 ) : after conditioning, test stimuli similar to the original CS can elicit the response, with strength proportional to similarity. In biological neural circuits, this process involves distinct anatomical pathways: sensory neurons carrying conditional stimulus (CS) information converge with those carrying unconditional stimulus (US) information at specific synaptic sites ( marenNeurobiologyPavlovianFear2001 ) , where Hebbian plasticity—"cells that fire together, wire together"—creates lasting associations ( hebbOrganizationBehaviorNeuropsychological1949 ; gerstnerMathematicalFormulationsHebbian2002 ) . This biological foundation suggests that effective learning systems should: (1) separate sensory inputs into distinct processing streams, (2) form associations through Hebbian rule. 3 Theoretical Framework Having established the biological principles of conditioning in the previous section, we now demonstrate how transformer attention implements these same computational principles in artificial neural networks. The key insight is that attention’s queries, keys, and values directly map onto the conditioning paradigm: