Linear Associative Memory in Transformer Feed-Forward Layers

This direction is merged into another direction: rank-one weight modification. Its last version stays readable and citable here.

Version 1 of 145 papers55 conceptsfrozen 2026-10-04

In the standard narrative of the Transformer, the self-attention mechanism is the protagonist. It is the "routing" engine that allows tokens to communicate across a sequence. But if attention is the router, what is the database? Recent research suggests that the answer lies in the Feed-Forward Networks (FFNs), which typically account for two-thirds of a model's total parameters.

Rather than acting as simple non-linear filters, these layers function as linear associative memories. This perspective, championed by researchers like Mor Geva and Damai Dai, reframes the two linear transformations within an FFN as a structured key-value retrieval system.

The Key-Value Mechanism

To understand why an FFN acts as a memory, we can look at its mathematical structure. An FFN layer typically performs a sequence of operations: $Output = f(x \cdot W_1) \cdot W_2$.

In the associative memory framework, the first weight matrix ($W_1$) acts as a set of keys. Each column in this matrix represents a specific pattern or concept the model has learned to recognize. When an input hidden state $x$ aligns with one of these keys, the corresponding neuron in the intermediate layer "fires."

The second weight matrix ($W_2$) acts as a set of values. Each row in $W_2$ is a vector that contains the information to be retrieved. When a "key" neuron is activated, it scales its corresponding "value" vector from $W_2$. These values are then summed and injected back into the model's residual stream.

As Mor Geva, Jonathan Berant, and colleagues argued in Transformer Feed-Forward Layers Are Key-Value Memories, this process is essentially a massive, soft lookup table. The first layer detects a feature (e.g., "this text is about the capital of France"), and the second layer provides the associated update (e.g., "promote the token 'Paris'").

Locating Knowledge Neurons

If FFNs are memory banks, can we find the specific "cells" where facts are stored? Damai Dai and Li Dong introduced the concept of knowledge neurons to answer this. In their work, Knowledge Neurons in Pretrained Transformers, they demonstrated that specific relational facts—like "the capital of Ireland is Dublin"—are often localized to a small number of neurons within the FFNs.

This localization isn't just a theoretical curiosity; it allows for surgical interventions. By identifying which neurons trigger for a specific fact, researchers can "edit" the model's memory. For instance, by modifying the weights associated with a specific knowledge neuron, one can change the model's internal "fact" about a subject without retraining the entire network.

Surgical Model Editing

The associative memory framing has led to powerful new techniques for model editing. If the FFN is a dictionary, we should be able to update its entries.

Kevin Meng and David Bau developed a method called ROME (Rank-One Model Editing), described in Locating and Editing Factual Associations in GPT. ROME treats the FFN as a linear associative memory and uses a closed-form solution to insert a new key-value pair into the weights. This allows a user to change a specific fact (e.g., "The Eiffel Tower is in Rome") with high precision and minimal "bleeding" into unrelated knowledge.

This was later scaled by Arnab Sen Sharma and others in Mass-Editing Memory in a Transformer. Their algorithm, MEMIT, can update thousands of facts simultaneously by treating the FFN layers as a structured repository where new information can be "written" into the parameter space.

Beyond Facts: Composition and Lexicons

The memory function of FFNs extends beyond simple trivia. Guy Kaplan and Roy Schwartz found that FFNs play a critical role in bridging the gap between sub-word tokens and full semantic meanings. In From Tokens to Words: On the Inner Lexicon of LLMs, they show that middle-layer FFNs act as an "inner lexicon," identifying patterns of tokens and retrieving the integrated word-level representation to inject back into the model's processing stream.

Even the way models learn during training can be viewed through this lens. Kazuki Irie and Róbert Csordás revisited the "dual form" of neural networks in The Dual Form of Neural Networks Revisited, proving that any linear layer trained via gradient descent is mathematically equivalent to a key-value memory system where the training inputs are the keys and the error signals are the values.

Why This Matters

Viewing Transformers as associative memories changes our intuition about how they "think." Instead of seeing a layer as a black-box transformation, we can see it as a structured retrieval process.

  1. Interpretability: As Mengyu Ye and Jun Suzuki noted in Transformer Key-Value Memories Are Nearly as Interpretable as Sparse Autoencoders, the weights themselves are often the most faithful map of the model's features.
  2. Control: We can mitigate hallucinations or biases by "re-anchoring" the model's internal memory, as seen in the MemVR approach by Xin Zou or the debiasing work of Tomasz Limisiewicz.
  3. Efficiency: Architectures like MemoryLLM by Ajay Jaiswal explore decoupling these memory layers entirely, allowing for models that are easier to update and more transparent in their factual recall.

By treating the FFN as a database, we move from merely observing model behavior to surgically understanding and managing the vast library of information stored within its weights.

Papers in this version

History & citationVersion 1 · 2026-10-04

Merged into another direction · Permanent link

View frozen version 1

Cite this direction

Latest version (a living page):

@misc{lacuna_linear_associative_memory_in_transformer_49a08f68,
  title = {Linear Associative Memory in Transformer Feed-Forward Layers},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/linear-associative-memory-in-transformer-feed-forward-layers/rdr_49a08f68aa104e22a38e2c1c11d011da},
  note = {Latest version of a living research direction; cite a version for a fixed text. Accessed 2026-11-27},
}

This exact version (version 1, frozen text):

@misc{lacuna_linear_associative_memory_in_transformer_49a08f68_v1,
  title = {Linear Associative Memory in Transformer Feed-Forward Layers},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/linear-associative-memory-in-transformer-feed-forward-layers/rdr_49a08f68aa104e22a38e2c1c11d011da/v/1},
  note = {Version 1, frozen 2026-10-04. Accessed 2026-11-27},
}