Scrub It Out! Erasing Sensitive Memorization in Code Language Models via Machine Unlearning

[Paper] Scrub It Out! Erasing Sensitive Memorization in Code Language Models via Machine Unlearning

A groundbreaking study introduces CodeEraser, a novel machine unlearning technique that addresses privacy vulnerabilities in Code Language Models (CLMs). This approach selectively erases sensitive information like passwords and API keys from CLMs without full retraining, achieving a 93.89% reduction in memorization while maintaining 99.00% of original performance. The method outperforms existing approaches, completing the process in just 47 seconds per sample. This research has significant implications for data protection regulations and the development of privacy-preserving AI systems. It offers a practical solution for organizations to comply with "Right to Be Forgotten" requests efficiently, paving the way for more trustworthy AI-powered software engineering tools.

Code Language Models (CLMs) have revolutionized software engineering by automating tasks like code generation, summarization, and program repair. However, a critical privacy vulnerability has emerged: these models often memorize and can reproduce sensitive information from their training data. A groundbreaking study published in ICSE ’26 addresses this problem through an innovative approach called “machine unlearning.” The research paper, available at https://arxiv.org/abs/2509.13755, demonstrates that sensitive information like passwords, API keys, and personal data can be selectively erased from CLMs while preserving their overall functionality.

The study, led by researchers Zhaoyang Chu, Yao Wan, and colleagues, introduces a novel technique called CodeEraser that can effectively remove specific sensitive information from CLMs without requiring full retraining. Their approach achieves a remarkable 93.89% reduction in memorization of targeted sensitive data while maintaining 99.00% of the model’s original performance, all within approximately 47 seconds per sample—dramatically more efficient than traditional retraining approaches that would require hundreds of GPU days.

Understanding the memorization problem in CLMs is crucial for appreciating the significance of this research. During their training process, CLMs like CodeGen, Code Llama, and Qwen2.5-Coder learn from vast amounts of code collected from GitHub repositories. Unfortunately, this training data often contains sensitive information such as personal identifiers, emails, passwords, and API keys. The researchers discovered that approximately 7% of training samples containing sensitive data were memorized by popular models like CodeParrot-small and CodeGen-350M-Mono, presenting substantial privacy risks.

Current approaches to mitigate memorization issues have significant limitations. Data de-duplication methods, which remove repeated instances from training data, can’t completely prevent memorization. Differential privacy techniques formally guarantee limited influence of individual data points but significantly degrade model performance by constraining the learning of rare patterns. Most importantly, both approaches would require complete retraining of the model to remove specific sensitive information, which is computationally prohibitive for large-scale CLMs, potentially requiring 900-1800 GPU days.

The CodeEraser approach introduced in this paper takes a fundamentally different direction by leveraging machine unlearning. Unlike existing techniques that indiscriminately forget entire code samples, CodeEraser selectively targets only the sensitive segments within code. The researchers first identify sensitive data using detection tools and then apply gradient ascent exclusively to sensitive segments to actively diminish their memorization while using gradient descent on surrounding non-sensitive code to preserve its integrity.

To evaluate their approach, the researchers constructed a comprehensive dataset of 50,000 sensitive memorized samples from various CLMs and established empirical thresholds for determining when information has been successfully “forgotten” by a model. They then compared CodeEraser against two baselines: a vanilla gradient ascent method and a constraint-based method.

The results across three families of CLMs (CodeParrot, CodeGen-Mono, and Qwen2.5-Coder) demonstrate CodeEraser’s superiority. For instance, with Qwen2.5-Coder-7B, CodeEraser achieved a 93.89% reduction in memorization while preserving 99.99% of the model’s code generation performance on the HumanEval benchmark. This significantly outperformed the baseline approaches, which showed performance degradations of up to 29% in some cases.

Interestingly, the research revealed that the characteristics of the targeted sensitive data—including the number of samples, their frequency in the training data, and the type of sensitive information—significantly influence unlearning effectiveness. For example, unlearning API/SSH keys sometimes actually improved model performance, likely because these atypical patterns functioned as outliers that previously distracted the model.

The implications of this research extend beyond technical achievements. As data protection regulations like the European Union’s GDPR and the California Consumer Privacy Act establish the “Right to Be Forgotten”, techniques like CodeEraser provide practical mechanisms for compliance. Organizations deploying CLMs can now respond to user requests to remove specific sensitive information without incurring the enormous computational costs of full retraining.

This pioneering study opens new avenues for research at the intersection of machine learning, privacy, and software engineering. By demonstrating that sensitive memorization can be selectively erased from CLMs efficiently and effectively, the researchers have made a significant contribution toward more privacy-preserving artificial intelligence systems. For developers interested in learning more about these concepts, Hands-On Large Language Models: Language Understanding and Generation provides excellent background on how these models work.

For developers and organizations working with large language models for code, this research offers a promising path forward: the ability to harness the power of CLMs while actively mitigating the risks of sensitive data exposure, ultimately creating more trustworthy AI systems for software engineering. Those concerned with implementing privacy in their software development practices may find Privacy for Software Engineers: A Practical Guide to Data Protection and Compliance a valuable resource for understanding best practices.

The selective unlearning approach demonstrated in CodeEraser represents a critical advancement in addressing the growing concerns about privacy and security in AI-powered development environments. For a deeper understanding of data privacy concepts in modern engineering, Data Privacy: A runbook for engineers offers practical strategies that complement the techniques discussed in this research.

For those interested in building their own language models with privacy considerations in mind, The Hundred-Page Language Models Book: hands-on with PyTorch provides accessible guidance on implementing state-of-the-art techniques while considering important ethical implications like those addressed by the CodeEraser research.

🚀 Unlock Ads-Free Experience At $5/year

14 days free trial Cancel anytime

54 thoughts on “[Paper] Scrub It Out! Erasing Sensitive Memorization in Code Language Models via Machine Unlearning”

  1. I like the practical angle here. Short browser-based games can work well when people want something easy to start and easy to leave, which is why Peak Game fits this context.

  2. I like the focus on making small technical tasks simpler. A browser-based utility such as Fd Calculator makes sense when installing software would be too much overhead.

Leave a Comment

Your email address will not be published. Required fields are marked *