In-Context Learning as Conditioned Associative Memory Retrieval

Abstract

We provide an exactly solvable example for interpreting In-Context Learning (ICL) with one-layer attention models as conditional retrieval of dense associative memory models. Our main contribution is to interpret ICL as memory reshaping in the modern Hopfield model from a conditional memory set (in-context examples). Specifically, we show that the in-context sequential examples induce an effective reshaping of the energy landscape of a Hopfield model. We integrate this in-context memory reshaping phenomenon into the existing Bayesian model averaging view of ICL [Zhang et al., AISTATS 2025] via the established equivalence between the modern Hopfield model and transformer attention. Under this unique perspective, we not only characterize how in-context examples shape predictions in the Gaussian linear regression case, but also recover the known $\epsilon$-stability generalization bound of the ICL for the one-layer attention model. We also give explanations for three key behaviors of ICL and validate them through experiments.

Cite

Text

Wu et al. "In-Context Learning as Conditioned Associative Memory Retrieval." Proceedings of the 42nd International Conference on Machine Learning, 2025.

Markdown

[Wu et al. "In-Context Learning as Conditioned Associative Memory Retrieval." Proceedings of the 42nd International Conference on Machine Learning, 2025.](https://mlanthology.org/icml/2025/wu2025icml-incontext-a/)

BibTeX

@inproceedings{wu2025icml-incontext-a,
  title     = {{In-Context Learning as Conditioned Associative Memory Retrieval}},
  author    = {Wu, Weimin and Hsiao, Teng-Yun and Hu, Jerry Yao-Chieh and Zhang, Wenxin and Liu, Han},
  booktitle = {Proceedings of the 42nd International Conference on Machine Learning},
  year      = {2025},
  pages     = {67300-67325},
  volume    = {267},
  url       = {https://mlanthology.org/icml/2025/wu2025icml-incontext-a/}
}