[Paper Review] Trained Without My Consent: Detecting Code Inclusion In Language Models Trained on Code
This paper proposes TraWiC, a model-agnostic and interpretable method that uses membership inference attacks to detect whether specific code from a project was included in a Large Language Model's training data. By masking syntactic and semantic identifiers (e.g., variable names, comments) and analyzing model predictions, TraWiC achieves 83.87% accuracy in detecting code inclusion—significantly outperforming NiCad, a standard clone detection tool, which reaches only 47.64% accuracy.
Code auditing ensures that the developed code adheres to standards, regulations, and copyright protection by verifying that it does not contain code from protected sources. The recent advent of Large Language Models (LLMs) as coding assistants in the software development process poses new challenges for code auditing. The dataset for training these models is mainly collected from publicly available sources. This raises the issue of intellectual property infringement as developers' codes are already included in the dataset. Therefore, auditing code developed using LLMs is challenging, as it is difficult to reliably assert if an LLM used during development has been trained on specific copyrighted codes, given that we do not have access to the training datasets of these models. Given the non-disclosure of the training datasets, traditional approaches such as code clone detection are insufficient for asserting copyright infringement. To address this challenge, we propose a new approach, TraWiC; a model-agnostic and interpretable method based on membership inference for detecting code inclusion in an LLM's training dataset. We extract syntactic and semantic identifiers unique to each program to train a classifier for detecting code inclusion. In our experiments, we observe that TraWiC is capable of detecting 83.87% of codes that were used to train an LLM. In comparison, the prevalent clone detection tool NiCad is only capable of detecting 47.64%. In addition to its remarkable performance, TraWiC has low resource overhead in contrast to pair-wise clone detection that is conducted during the auditing process of tools like CodeWhisperer reference tracker, across thousands of code snippets.
Motivation & Objective
- Address the challenge of auditing code generated by LLMs when training datasets are not publicly accessible.
- Overcome the limitations of traditional code clone detection tools like NiCad, which require access to original training data and are ineffective for hidden dataset inclusion.
- Develop a method that detects code inclusion without requiring retraining or access to the original model’s training data.
- Enable interpretable and efficient detection of intellectual property infringement in code LLMs, especially for obfuscated or non-syntactic code elements.
- Provide a scalable and resource-efficient alternative to pair-wise clone detection for auditing LLM-generated code.
Proposed method
- Extract unique syntactic and semantic identifiers (e.g., variable names, function names, comments, strings) from code files in a project.
- Mask these identifiers in the code and query the target LLM to predict the masked elements.
- Train a membership inference classifier using the model’s output predictions to determine if the original code was present in the training dataset.
- Use a surrogate model to simulate membership inference behavior and train the classifier without access to the original training data.
- Leverage the memorization property of LLMs, where models can reproduce training instances, to detect inclusion via statistical analysis of prediction confidence.
- Apply the method to non-syntactic elements (e.g., rare variable names, documentation strings) to improve detection robustness against obfuscation.
Experimental results
Research questions
- RQ1Can membership inference attacks effectively detect whether a given code project was included in an LLM’s training dataset without access to the training data?
- RQ2How does TraWiC’s performance compare to traditional code clone detection tools like NiCad in detecting dataset inclusion?
- RQ3To what extent can TraWiC detect code inclusion when the code is obfuscated or modified in non-syntactic ways (e.g., renaming variables, altering comments)?
- RQ4What role do infrequent or semantic identifiers (e.g., rare variable names, documentation strings) play in improving detection accuracy?
- RQ5How efficient and scalable is TraWiC compared to pair-wise clone detection methods in large-scale auditing scenarios?
Key findings
- TraWiC achieves a detection accuracy of 83.87% in identifying whether a project’s code was included in an LLM’s training dataset.
- NiCad, a widely used clone detection tool, achieves only 47.64% accuracy in the same task, demonstrating that TraWiC significantly outperforms traditional approaches.
- TraWiC demonstrates high recall—up to 99.19%—indicating strong sensitivity in detecting included code, even in complex or obfuscated cases.
- The method is robust to noise and code obfuscation, particularly when targeting less common identifiers such as rare variable names or documentation strings.
- TraWiC has low computational overhead compared to pair-wise clone detection, as it avoids the need for exhaustive comparison across thousands of code snippets.
- The approach is model-agnostic and interpretable, enabling deployment across various code LLMs without retraining or access to the original training data.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.