TL;DR
When an LLM recites a string, is it parroting what it memorized or genuinely understanding the underlying language? This paper introduces contextual memorization to cleanly separate rote memorization from language learning, showing that some memorization is actually unavoidable if you want an LLM to learn a language well. Armed with this insight, the authors propose memorization-aware training (MAT), a simple dynamic down-sampling trick that cuts memorization, stabilizes learning, and reduces training cost.
What Problem Does This Paper Address?
If you ask an LLM to count from 1 to 1000 and it succeeds, did it "memorize" that sequence? Probably not—it learned the pattern. Yet most existing memorization metrics (recollection-based measures) simply check whether a model can spit back a training string with low loss. That conflates genuine contextual learning with rote memorization.
The authors tackle three foundational questions about how these two forces interact during training:
- When does an LLM actually begin memorizing a specific training string?
- Can an LLM learn a language optimally without memorizing any training strings?
- If memorization is unavoidable, can we design a training scheme that reduces it while improving learning?
Methods
Contextual Memorization. Imagine an English speaker and a German speaker memorizing a German paragraph. The German speaker already understands the grammar and syntax, so they rely far less on rote memorization than the English speaker. To capture this, the authors define contextual memorization for a training string $s$: they measure the lowest loss $s$ could achieve if it were excluded from the training set (its "optimal contextual loss," learned purely from the rest of the language). A string is only considered contextually memorized once its training loss drops below this optimal contextual threshold. Because retraining without each string is expensive, they also show that test strings from the same frequency group can serve as an accurate proxy.
Memorization-Aware Training (MAT). Since different strings are memorized at different epochs, standard training leads to uneven learning across test strings. MAT fixes this with a lightweight heuristic: at each epoch, it computes $x\%$, the fraction of test strings whose loss just increased, and dynamically down-samples the $x\%$ of training strings with the lowest loss (the ones already learned or memorized). If a down-sampled string is later forgotten (its loss rises), it re-enters training at a future epoch.
Datasets
- Formal Languages (Primary Testbed): 10 probabilistic and hierarchical context-free languages (PCFLs) of varying entropy, alphabet (numerical and Latin tokens), and size. Using formal languages gives exact control over grammar rules, string frequencies, and entropy, while completely eliminating data contamination.
- Natural Languages (Validation): Results are further validated on natural language datasets across English, German, Chinese, Swahili, and Bengali.
- Models: 18 open-source LLMs from 6 families (Mistral, Llama, Qwen, Gemma, Pythia, Opt), ranging from 0.5B to 13B parameters, with main-paper results focusing on Mistral-7B.
Key Insights and Ideas
- Memorization metrics disagree—sharply: Recollection-based measures say frequent strings are memorized first because they cross a fixed loss threshold sooner. Contextual and counterfactual measures often say the opposite: frequent strings share more grammar rules with other strings, so they have a lower optimal contextual loss and take more epochs to be contextually memorized.
- You can't learn without memorizing: Across both high- and low-entropy languages, the epoch of optimal language learning ($e^*$) consistently falls after many strings have already been memorized. Some memorization is unavoidable for optimal learning.
- More data reduces contextual memorization: Larger training datasets improve language fluency, which lowers the optimal contextual loss. Even though strings repeat more (which fools recollection-based metrics into flagging more memorization), contextual memorization actually decreases.
Key Results
- More stable and uniform learning: On Mistral-7B (e.g., language $L_2$), MAT lowers mean test loss (from
0.1902to0.1807) and consistently reduces the standard deviation of test loss across strings compared to base training and deduplication. - Lower memorization and training cost: MAT reduces weighted contextual memorization at the optimal learning epoch and significantly cuts the effective number of training strings processed.
- Dynamic beats static: Static deduplication balances string frequency, but still suffers from local overfitting on "easier" strings. MAT's dynamic down-sampling adapts to actual learning progress.
Limitations and Future Work
- The analysis is organized primarily around string frequency; other properties like syntactic complexity or entropy likely also shape memorization.
- Computing exact contextual memorization is expensive, and the frequency-based proxy could be improved with alternative approximation schemes.
- MAT uses a simple loss-based down-sampling heuristic, and the authors note that validating their formal-language findings on a wider range of natural language settings remains important future work.
Summary updated