Memorize or Generalize? Evaluating LLM Code Generation with Code Rewriting
Not on the map. Why?
Abstract (arXiv)
Large language models (LLMs) have recently demonstrated exceptional code generation capabilities. However, there is a growing debate whether LLMs are mostly doing memorization (i.e., replicating or reusing large parts of their training data) versus generalization (i.e., beyond training data). Existing evaluations largely proxy memorization with surface/structural similarity, thereby conflating benign reuse of repeated code with harmful recall and neglecting task correctness under semantic variation. We define harmful memorization behaviorally as failure at high similarity and introduce a semantic perturbation code rewriting, which rewrites a semantically different answer at a similar difficulty level for a given coding task, then reverse-engineers a novel coding task. We further propose Memorization Risk Index (MRI), a normalized score that combines two signals: (i) how similar the model's answer for the rewritten task is to the original ground-truth solution, and (ii) how much performance drops from the original task to its rewritten counterpart. MRI is high only when both conditions hold -- when the model outputs similar code but fails the perturbed task -- thereby capturing harmful memorization rather than benign reuse of repeated code. Empirical evaluations on code generation benchmarks MBPP+ and BigCodeBench reveal that (1) memorization does not increase with larger models and in many cases alleviates as they scale; (2) supervised fine-tuning (SFT) improves accuracy while introduces memorization; (3) reinforcement learning with proximal policy optimization (PPO) achieves a more balanced trade-off between memorization and generalization.
Key facts. Cited by 7 papers in the map (data through 14 Oct 2026). Builds on 26 of its 34 references that are in the map. First posted on arXiv 4 Mar 2025.
Builds on
26 of 34 references.
References · 26
- 2017Proximal Policy Optimization Algorithmscited by 15,215
- 2024The Llama 3 Herd of Modelscited by 14,715
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2023Direct Preference Optimization: Your Language Model is Secretly a Reward Modelcited by 8,065
- 2024LiveCodeBench: Holistic and Contamination Free Evaluation of Large Language Models for Codecited by 2,004
- 2022Competition-Level Code Generation with AlphaCodecited by 1,462
- 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,391
- 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,181
- 2018The Secret Sharer: Evaluating and Testing Unintended Memorization in Neural Networkscited by 864
- 2024BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructionscited by 546
- 2022DS-1000: A Natural and Reliable Benchmark for Data Science Code Generationcited by 452
- 2023Beyond Memorization: Violating Privacy Via Inference with Large Language Modelscited by 175
14 more
- 2024Generalization or Memorization: Data Contamination and Trustworthy Evaluation for Large Language Modelscited by 122
- 2024On Memorization of Large Language Models in Logical Reasoningcited by 117
- 2022ReCode: Robustness Evaluation of Code Generation Modelscited by 103
- 2019Analyzing Information Leakage of Updates to Natural Language Modelscited by 90
- 2024Quantifying Contamination in Evaluating Code Generation Capabilities of Language Modelscited by 65
- 2023On the Robustness of Code Generation Techniques: An Empirical Study on GitHub Copilotcited by 64
- 2024Alpaca against Vicuna: Using LLMs to Uncover Memorization of LLMscited by 33
- 2024Scaling Laws for Fact Memorization of Large Language Modelscited by 33
- 2023Unveiling Memorization in Code Modelscited by 30
- 2023Traces of Memorisation in Large Language Models for Codecited by 29
- 2024Unlocking Memorization in Large Language Models with Dynamic Soft Promptingcited by 21
- 2024NLPerturbator: Studying the Robustness of Code LLMs to Natural Language Variationscited by 20
- 2024The Pitfalls of Memorization: When Memorization Hurts Generalizationcited by 19
- 2024Measuring memorization in RLHF for code completioncited by 13
Built on by
Citing papers per year: 2025: 3; 2026: 4.
7 papers.
- 2025The SWE-Bench Illusion: When State-of-the-Art LLMs Remember Instead of Reasoncited by 49
- 2025Throttling Web Agents Using Reasoning Gatescited by 2
- 2026Evaluating LLM-Based Test Generation Under Software Evolutioncited by 2
- 2026Precise Debugging Benchmark: Is Your Model Debugging or Regenerating?cited by 2
- 2026Detecting Functional Memorization in Code Language Modelscited by 1
- 2025Answer-Centric or Reasoning-Driven? Uncovering the Latent Memory Anchor in LLMscited by 0
- 2026Beyond the Training Distribution: Mapping Generalization Boundaries in Neural Program Synthesiscited by 0
- 2026Detecting Functional Memorization in Code Language Models11 Jun 2026
- 2026Beyond the Training Distribution: Mapping Generalization Boundaries in Neural Program Synthesis30 Apr 2026
- 2026Precise Debugging Benchmark: Is Your Model Debugging or Regenerating?19 Apr 2026
- 2026Evaluating LLM-Based Test Generation Under Software Evolution24 Mar 2026
- 2025Throttling Web Agents Using Reasoning Gates1 Sep 2025
- 2025Answer-Centric or Reasoning-Driven? Uncovering the Latent Memory Anchor in LLMs21 Jun 2025
- 2025The SWE-Bench Illusion: When State-of-the-Art LLMs Remember Instead of Reason14 Jun 2025
Similar, not cited
Close in wording, no citation either way
- 2026Memorization Diagnostics for Code LLMs Should be Scale-Aware
- 2025The Landscape of Memorization in LLMs: Mechanisms, Measurement, and Mitigation
- 2026Are you Synthesizing or Recalling? Evaluating LLMs on Algorithmic Code Retrieval
- 2024CodeLutra: Boosting LLM Code Generation via Preference-Guided Refinement
- 2025Leaner Training, Lower Leakage: Revisiting Memorization in LLM Fine-Tuning with LoRA
- 2025Analyzing Memorization in Large Language Models through the Lens of Model Attribution
- 2024Towards Effective Evaluations and Comparisons for LLM Unlearning Methods
- 2024Rethinking Code Refinement: Learning to Judge Code Efficiency