mlsanityData to 14 Oct 2026

Memorize or Generalize? Evaluating LLM Code Generation with Code Rewriting

arXiv 2503.02296 ↗First posted 4 Mar 2025cs.AIcited by 7

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

  1. 2017Proximal Policy Optimization Algorithmscited by 15,215
  2. 2024The Llama 3 Herd of Modelscited by 14,715
  3. 2021Evaluating Large Language Models Trained on Codecited by 8,320
  4. 2023Direct Preference Optimization: Your Language Model is Secretly a Reward Modelcited by 8,065
  5. 2024LiveCodeBench: Holistic and Contamination Free Evaluation of Large Language Models for Codecited by 2,004
  6. 2022Competition-Level Code Generation with AlphaCodecited by 1,462
  7. 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,391
  8. 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,181
  9. 2018The Secret Sharer: Evaluating and Testing Unintended Memorization in Neural Networkscited by 864
  10. 2024BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructionscited by 546
  11. 2022DS-1000: A Natural and Reliable Benchmark for Data Science Code Generationcited by 452
  12. 2023Beyond Memorization: Violating Privacy Via Inference with Large Language Modelscited by 175
14 more
  1. 2024Generalization or Memorization: Data Contamination and Trustworthy Evaluation for Large Language Modelscited by 122
  2. 2024On Memorization of Large Language Models in Logical Reasoningcited by 117
  3. 2022ReCode: Robustness Evaluation of Code Generation Modelscited by 103
  4. 2019Analyzing Information Leakage of Updates to Natural Language Modelscited by 90
  5. 2024Quantifying Contamination in Evaluating Code Generation Capabilities of Language Modelscited by 65
  6. 2023On the Robustness of Code Generation Techniques: An Empirical Study on GitHub Copilotcited by 64
  7. 2024Alpaca against Vicuna: Using LLMs to Uncover Memorization of LLMscited by 33
  8. 2024Scaling Laws for Fact Memorization of Large Language Modelscited by 33
  9. 2023Unveiling Memorization in Code Modelscited by 30
  10. 2023Traces of Memorisation in Large Language Models for Codecited by 29
  11. 2024Unlocking Memorization in Large Language Models with Dynamic Soft Promptingcited by 21
  12. 2024NLPerturbator: Studying the Robustness of Code LLMs to Natural Language Variationscited by 20
  13. 2024The Pitfalls of Memorization: When Memorization Hurts Generalizationcited by 19
  14. 2024Measuring memorization in RLHF for code completioncited by 13

Built on by

Cited by year (2026 to 14 Oct)

Citing papers per year: 2025: 3; 2026: 4.

7 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2026Memorization Diagnostics for Code LLMs Should be Scale-Aware
  2. 2025The Landscape of Memorization in LLMs: Mechanisms, Measurement, and Mitigation
  3. 2026Are you Synthesizing or Recalling? Evaluating LLMs on Algorithmic Code Retrieval
  4. 2024CodeLutra: Boosting LLM Code Generation via Preference-Guided Refinement
  5. 2025Leaner Training, Lower Leakage: Revisiting Memorization in LLM Fine-Tuning with LoRA
  6. 2025Analyzing Memorization in Large Language Models through the Lens of Model Attribution
  7. 2024Towards Effective Evaluations and Comparisons for LLM Unlearning Methods
  8. 2024Rethinking Code Refinement: Learning to Judge Code Efficiency