Understanding the Interplay between Memorization and Learning in Large Language Models
Organizations: Max Planck Institute for Software Systems, Germany · Boston University, USA
Abstract
We investigate foundational questions about the interplay between memorization and learning in large language models (LLMs). When an LLM generates a string, can we disentangle the roles of rote memorization and contextual learning? Rote memorization results in an LLM regurgitating specific details of a training string, while contextual learning leads to the generation of new strings that follow generalizable patterns of the underlying language. Related questions of interest include: can an LLM avoid memorization when optimally learning a language?, and if not, can we design training schemes to reduce memorization and improve learning? To address these questions, we propose contextual memorization, a new measure that precisely disentangles memorization from learning. Using this measure, we establish that different training strings are memorized at different epochs in training, and that memorization of some training strings is unavoidable when optimally learning a language. Finally, we propose memorization-aware training, a scheme that dynamically down-samples training strings based on their memorization, and in doing so, equalizes learning across strings, reduces memorization, and improves learning. Our conclusions are supported by extensive experiments on multiple LLMs using formal languages as a controlled testbed, enabling precise language specification, exact string sampling, and elimination of data contamination; and further validated on natural languages.
Figures & tables
Appendix figures & tables62 assets
Supplementary material from the paper’s appendix.
Appendix
| Memorization Measure | Motivation | Memorization Threshold | Ease of Operationalization | Strictness of Measure |
|---|---|---|---|---|
| Recollection | Disclosing private information | Manual | Easy | Variable |
| Counterfactual | Differential privacy | Adaptive | Hard | Medium |
| Contextual (ours) | Local over-fitting | Adaptive | Hard | High |
| \displaystyle{\color[rgb]{1,0,0}S}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A16}\;{\color[rgb]{0,0,1}[1]} | |||
| \displaystyle{\color[rgb]{1,0,0}A16}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A15}\;{\color[rgb]{1,0,0}A14}\;{\color[rgb]{1,0,0}A13}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A16}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A13}\;{\color[rgb]{1,0,0}A15}\;{\color[rgb]{1,0,0}A14}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A13}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A13}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A14}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{1,0,0}A10}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A14}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A10}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{0,0,1}[0.50]} |
| \displaystyle{\color[rgb]{1,0,0}S}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}S5}\;{\color[rgb]{0,0,1}[1]} | |||
| \displaystyle{\color[rgb]{1,0,0}S5}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}B4}\;{\color[rgb]{1,0,0}C1_{1}}\;{\color[rgb]{1,0,0}E4}\;{\color[rgb]{1,0,0}T1_{1}}\;{\color[rgb]{0,0,1}[0.25]} | |||
| \displaystyle{\color[rgb]{1,0,0}S5}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}B4}\;{\color[rgb]{1,0,0}C1_{2}}\;{\color[rgb]{1,0,0}E4}\;{\color[rgb]{1,0,0}T1_{2}}\;{\color[rgb]{0,0,1}[0.25]} | |||
| \displaystyle{\color[rgb]{1,0,0}S5}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}B4}\;{\color[rgb]{1,0,0}C1_{3}}\;{\color[rgb]{1,0,0}E4}\;{\color[rgb]{1,0,0}T1_{3}}\;{\color[rgb]{0,0,1}[0.25]} | |||
| \displaystyle{\color[rgb]{1,0,0}S5}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}B4}\;{\color[rgb]{1,0,0}C1_{4}}\;{\color[rgb]{1,0,0}E4}\;{\color[rgb]{1,0,0}T1_{4}}\;{\color[rgb]{0,0,1}[0.25]} | |||
| \displaystyle{\color[rgb]{1,0,0}B4}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}B3}\;{\color[rgb]{0,0,1}[0.3333]} | |||
| \displaystyle{\color[rgb]{1,0,0}B4}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}B3}\;{\color[rgb]{1,0,0}B3}\;{\color[rgb]{1,0,0}B3}\;{\color[rgb]{0,0,1}[0.3333]} |
| \displaystyle{\color[rgb]{1,0,0}S}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A16}\;{\color[rgb]{0,0,1}[1]} | |||
| \displaystyle{\color[rgb]{1,0,0}A16}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A15}\;{\color[rgb]{1,0,0}A13}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A16}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A13}\;{\color[rgb]{1,0,0}A15}\;{\color[rgb]{1,0,0}A14}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A13}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A13}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A14}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{1,0,0}A10}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A14}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A10}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{0,0,1}[0.50]} |
| \displaystyle{\color[rgb]{1,0,0}S}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A16}\;{\color[rgb]{0,0,1}[1]} | |||
| \displaystyle{\color[rgb]{1,0,0}A16}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A15}\;{\color[rgb]{1,0,0}A13}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A16}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A13}\;{\color[rgb]{1,0,0}A15}\;{\color[rgb]{1,0,0}A14}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A13}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A13}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A14}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{1,0,0}A10}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{0,0,1}[0.50]} | |||
| \displaystyle{\color[rgb]{1,0,0}A14}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A10}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{0,0,1}[0.50]} |
| \displaystyle{\color[rgb]{1,0,0}S}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A13}\;{\color[rgb]{0,0,1}[1]} | |||
| \displaystyle{\color[rgb]{1,0,0}A13}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A10}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{0,0,1}[0.8413447461]} | |||
| \displaystyle{\color[rgb]{1,0,0}A13}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A9}\;{\color[rgb]{1,0,0}A10}\;{\color[rgb]{0,0,1}[0.1586552539]} | |||
| \displaystyle{\color[rgb]{1,0,0}A12}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A5}\;{\color[rgb]{1,0,0}A7}\;{\color[rgb]{1,0,0}A5}\;{\color[rgb]{1,0,0}A8}\;{\color[rgb]{0,0,1}[0.8413447461]} | |||
| \displaystyle{\color[rgb]{1,0,0}A12}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A6}\;{\color[rgb]{1,0,0}A6}\;{\color[rgb]{0,0,1}[0.1586552539]} | |||
| \displaystyle{\color[rgb]{1,0,0}A11}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A5}\;{\color[rgb]{1,0,0}A7}\;{\color[rgb]{1,0,0}A8}\;{\color[rgb]{0,0,1}[0.8413447461]} | |||
| \displaystyle{\color[rgb]{1,0,0}A11}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A6}\;{\color[rgb]{0,0,1}[0.1586552539]} |
| \displaystyle{\color[rgb]{1,0,0}S}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A19}\;{\color[rgb]{0,0,1}[1]} | |||
| \displaystyle{\color[rgb]{1,0,0}A19}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{1,0,0}A18}\;{\color[rgb]{1,0,0}A14}\;{\color[rgb]{1,0,0}A17}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{1,0,0}A17}\;{\color[rgb]{1,0,0}A15}\;{\color[rgb]{1,0,0}A10}\;{\color[rgb]{0,0,1}[0.16335]} | |||
| \displaystyle{\color[rgb]{1,0,0}A19}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A15}\;{\color[rgb]{1,0,0}A13}\;{\color[rgb]{0,0,1}[0.2032909216]} | |||
| \displaystyle{\color[rgb]{1,0,0}A19}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A10}\;{\color[rgb]{1,0,0}A12}\;{\color[rgb]{0,0,1}[0.2376710982]} | |||
| \displaystyle{\color[rgb]{1,0,0}A19}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A18}\;{\color[rgb]{0,0,1}[0.2594097969]} | |||
| \displaystyle{\color[rgb]{1,0,0}A19}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A16}\;{\color[rgb]{1,0,0}A15}\;{\color[rgb]{1,0,0}A15}\;{\color[rgb]{0,0,1}[0.1346583572]} | |||
| \displaystyle{\color[rgb]{1,0,0}A19}\;{\color[rgb]{0,0,0}\rightarrow}\;{\color[rgb]{1,0,0}A11}\;{\color[rgb]{1,0,0}A18}\;{\color[rgb]{1,0,0}A13}\;{\color[rgb]{1,0,0}A10}\;{\color[rgb]{0,0,1}[0.0016209134]} |
| Prompt + Generation | Accuracy of Generation | Remark | |
|---|---|---|---|
| Training | |||
| ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( | Repetitions | ||
| orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum l orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum l | Repeated L a T e X code | ||
| 29, int t30, int t31, int t32, int t33, int t34, int t35, int t36, int t 37, int t38, int t39, int t40, int t41, int t42, int t43, int t44, int t | Predictable | ||
| ICO CITY PLEASE COME TO MEXICO CITY PLEASE COME TO MEXICO CITY PLEASE COME TO MEXICO CITY PLEASE COM E TO MEXICO CITY PLEASE COME TO MEXICO CITY PLEASE COME TO MEXICO CITY PLEASE COME TO MEXICO | Repetition | ||
| , ’2014-07-22’ , ’2014-07-23’ , ’2014-07-24’ , ’2014-07-25’ , ’2014-07-26’ , ’2014-07-27’ , ’2014-07-28’ , ’2014-07-29’ | Predictable | ||
Memorization in Language Models
Memorization in language models studies how training examples and facts are stored, recalled, generalized, and exposed by model parameters.
See all 111 papers