Do LLMs dream of elephants (when told not to)? Latent concept association and associative memory in transformers

Yibo Jiang, Goutham Rajendran, Pradeep Ravikumar, Bryon Aragam · DOI

Introduction: The Fragility of LLM Recall

Large Language Models (LLMs) are often lauded for their vast knowledge bases, yet they exhibit a peculiar fragility when faced with misleading contexts. A human asked, "The Eiffel Tower is not in Chicago; it is in the city of..." will immediately identify Paris. However, models such as GPT-2, LLaMA, and Gemma frequently succumb to "context hijacking," where the mere presence of a distractor like "Chicago" overrides the factual retrieval of "Paris," even when the prompt explicitly negates the distractor.

This paper investigates the underlying mechanics of this phenomenon, proposing that transformers function primarily as associative memory systems. By analyzing how models aggregate "clues" from a context to trigger specific outputs, the authors provide a theoretical and empirical foundation for understanding why LLMs are so easily misled.

Context Hijacking and the Associative Memory Model

The researchers define "context hijacking" as the process where irrelevant or contradictory tokens in a prompt steer the model toward an incorrect output. This behavior suggests a gap between the idealized view of LLMs as reasoning agents and their actual operation as associative memories.

In this view, the transformer does not "reason" through the negation ("is not in Chicago"); instead, the self-attention mechanism treats "Chicago" as a high-weight clue. This clue then triggers the retrieval of associated information stored within the model's weights. To study this formally, the authors introduced the Latent Concept Association (LCA) task. In LCA, tokens are associated not through direct similarity, but via a shared latent semantic space, where similarity is measured by the Hamming distance between binary vectors representing specific concepts.

The Architecture of Memory: The Centrality of $W_V$

A key contribution of this research is the re-evaluation of the value matrix ($W_V$) in the transformer block. While often dismissed as a simple linear projection, the authors demonstrate that $W_V$ is the engine of associative memory.

Through theoretical modeling of a one-layer transformer, the authors proved that while the self-attention layer acts as a filter to gather statistics from the context, the value matrix performs the actual mapping of these context clues to the correct output token. To validate this, they conducted an "identity crisis" experiment: replacing the trained $W_V$ with an identity matrix caused the model's performance on the LCA task to collapse. Conversely, a $W_V$ constructed based on their theoretical framework maintained high accuracy, confirming that the memory is indeed stored within these weights.

Geometric Insights and Low-Rank Emergence

The study also sheds light on the geometry of LLM embeddings. In underparameterized settings—where the embedding dimension is smaller than the total vocabulary—the model learns a specific geometric arrangement. The inner product between token embeddings becomes linearly related to their Hamming distance in the latent concept space.

Furthermore, the researchers observed the natural emergence of low-rank structures within the embedding space. This provides a robust theoretical justification for the efficacy of Low-Rank Adaptation (LoRA) in fine-tuning. The models inherently organize information in a low-rank manner, making them particularly susceptible to efficient weight updates that target these specific dimensions.

Empirical Results: From Synthetic Tasks to Real-World Models

The authors tested their hypotheses using the CounterFact dataset, which contains over 21,000 counterfactual assertions. Their "red-teaming" experiments showed that prepending a "hijacking" phrase like "Do not think of [False Target]" significantly increased the probability of the model outputting that target. As the number of repetitions of the hijacking phrase increased, the "Efficacy Score" of the attack skyrocketed across GPT-2, LLaMA-2, and Gemma.

These results were mirrored in the synthetic LCA datasets, where the researchers could precisely control parameters like context length and signal-to-noise ratio. The alignment between the theoretical "principal angles" of their constructed matrices and the actual trained matrices was remarkably high, suggesting that their 1-layer model captures the fundamental building blocks of transformer behavior.

Limitations and Future Directions

While the paper provides a compelling look into the "black box" of transformers, it focuses primarily on single-layer models. Multi-layer architectures involve more complex interactions, such as induction heads, which are not fully accounted for in this theoretical framework. Additionally, the synthetic LCA task, while mathematically rigorous, does not capture the full grammatical and sequential complexity of natural language.

Future research may extend these findings to deeper architectures and more structured data distributions, potentially leading to more robust models that are less susceptible to the "elephants" they are told to ignore.

Summary updated

BibTeX
@inproceedings{jiang2024do,
  author = {Yibo Jiang and Goutham Rajendran and Pradeep Ravikumar and Bryon Aragam},
  title = {{Do LLMs dream of elephants (when told not to)? Latent concept association and associative memory in transformers}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=WJ04ZX8txM},
}
Figure