TL;DR
This paper introduces CoDEMI, a novel membership inference technique adapted for neural code completion models. It addresses the critical question of whether a user's code was used to train these models, which is crucial for intellectual property protection and preventing sensitive data leakage. CoDEMI achieves good accuracy on smaller models like LSTM and CodeGPT but faces challenges with larger, more generalized language models.
What Problem Does This Paper Address?
The widespread use of open-source code, particularly from platforms like GitHub, to train powerful deep learning models for code completion (e.g., GitHub Copilot, CodeGPT, StarCoder) raises significant legal and ethical concerns. Developers and organizations need to know if their code, potentially under specific licenses or containing sensitive information, has been incorporated into these training datasets. This knowledge is vital for:
- Safeguarding Intellectual Property: Ensuring that proprietary code isn't unknowingly used to train commercial models without proper attribution or licensing.
- Preventing Sensitive Data Leakage: Identifying if personal or confidential information embedded in code snippets (like passwords, API keys, or PII) has been memorized by the model and could be exfiltrated.
Existing methods for membership inference are often designed for classification tasks and struggle with the sequential and generative nature of code completion models, which operate as "black boxes" with limited output information.
Methods
The core of the paper is the CoDEMI (Code Membership Inference) approach, which adapts membership inference techniques for code completion. It operates in a black-box setting, meaning it only has access to the target model's inputs and outputs, not its internal parameters or training data. The key steps are:
- Shadow Model Training: Since the target model's architecture and parameters are unknown, CoDEMI trains multiple "shadow" models that mimic the behavior of the target model. These shadow models are trained on publicly available code datasets.
- Membership Classifier Training: The outputs (probability vectors) from the shadow models, when queried with "member" (training) and "non-member" (testing) data, are used to train a binary membership classifier. Instead of raw probabilities, CoDEMI uses the ranks of the predicted tokens, as real-world interfaces often truncate full probability distributions.
- Membership Inference: The trained classifier takes the output of the target model (for a given code sample) and predicts whether that sample was part of the target model's training data.
Datasets
- Py150: A dataset of 150,000 Python source code files from GitHub repositories, used for training both target and shadow models.
- CodeSearchNet: Used for training CodeGen and StarCoder target models.
- The Stack: A large corpus of code used for pre-training CodeGen and StarCoder.
- Github-Python: A curated dataset of Python files from GitHub (created after January 1, 2023, with at least 20 stars), used as non-member data for CodeGPT, CodeGen, and StarCoder.
Key Insights and Ideas
- Ranks Over Probabilities: Using the rank of predicted tokens, rather than raw probabilities, is a more practical and effective feature for membership inference in code completion, aligning better with how users interact with these tools.
- Shadow Models Mimic Behavior: The success of CoDEMI hinges on the ability of shadow models to accurately replicate the target model's output behavior, even without knowing its internal workings.
- LLMs are Harder to Probe: Larger language models (LLMs) like CodeGen and StarCoder, due to their extensive training and strong generalization capabilities, are significantly more resistant to membership inference attacks compared to smaller, more specialized models like LSTM and CodeGPT. This suggests they might be less prone to memorizing specific training examples.
- Overfitting and Memorization: The effectiveness of CoDEMI on LSTM and CodeGPT is linked to their tendency to overfit and memorize less frequent tokens from the training data, creating discernible behavioral differences between member and non-member data.
Key Results
- LSTM-based Model: CoDEMI achieved an accuracy of 0.842 and an AUC of 0.902 when targeting an LSTM-based code completion model.
- CodeGPT Model: CoDEMI achieved an accuracy of 0.730 and an AUC of 0.804 when targeting the CodeGPT model.
- CodeGen and StarCoder: Performance dropped significantly for these LLMs, indicating challenges in detecting membership.
- Number of Shadow Models: The approach performs comparably well with as few as 2-4 shadow models, suggesting that a large number isn't strictly necessary.
- Number of Queries: The frequency-based sampling strategy for queries achieved comparable performance with fewer queries (around 20) compared to random sampling (requiring ~40-160 queries).
Limitations and Future Work
- LLM Generalization: The primary limitation is the difficulty in applying CoDEMI to highly generalized LLMs like CodeGen and StarCoder, which exhibit strong generalization and less memorization. Further research is needed to improve inference for these models.
- Non-Member Dataset Assurance: It's challenging to definitively ensure that the non-member datasets do not contain any elements from the target model's training data, which could introduce bias.
- Limited Target Models: The study focused on four specific models. Future work could extend validation to other code completion and generation models (e.g., ChatGPT, Code Llama).
- Dataset Diversity: The experiments were primarily conducted on Python datasets. Evaluating CoDEMI on code from different programming languages is a future direction.
- Model Memorization: While the paper discusses memorization as a factor, a deeper understanding of how LLMs memorize and how this can be exploited for membership inference is an ongoing area.
Summary updated