Unlearnable Examples: Protecting Open-Source Software from Unauthorized Neural Code Learning

Zhenlan Ji, Pingchuan Ma, Shuai Wang

Abstract

As AI-powered code assistants like GitHub Copilot become ubiquitous, concerns regarding the unauthorized use of open-source code for training have intensified. This paper introduces a framework to create "unlearnable" code—software that remains fully functional and readable for humans but effectively "blinds" neural models during training. By applying a sequence of lightweight, semantics-preserving transformations, the authors demonstrate a significant degradation in the performance of code autocompletion models without impacting the software's utility or developer experience.

Introduction

The rise of "AI pair programmers" has sparked a heated debate over copyright and consent. While many open-source licenses (like BSD or MIT) allow public access, they often require attribution or restrict commercial exploitation. Currently, developers lack technical means to prevent their code from being "absorbed" into a model's weights once published online.

Unlike images, where imperceptible "noise" can fool a model, code is brittle; changing even a single character can break logic or prevent compilation. This research seeks to apply "digital camouflage" to code: making it look like noise to a neural network's embedding space while keeping it perfectly clear to a human programmer.

Methods

The authors propose a framework that applies a series of lightweight, semantics-preserving transformations. Instead of heavy obfuscation, which ruins readability, they utilize three levels of subtle changes:

  1. Identifier Level: Replacing variable names with synonyms or random strings.
  2. Constant Level: Rewriting numbers or strings into equivalent expressions (e.g., changing 10 to 121 - 111).
  3. Statement Level: Inserting "dead code" or redundant declarations that do not affect the output but complicate the program's Abstract Syntax Tree (AST).
Table of semantics-preserving transformation methods across three levels: Identifier, Constant, and Statement.

To optimize these changes, the authors use a Multi-Armed Bandit (ε-Greedy) algorithm. This iterative process searches for a transformation sequence that maximizes the "embedding distance" (how different the code looks to an AI model like CodeBERT) while minimizing the "edit distance" to ensure human readability. A local "guide" model predicts how much a change will confuse a larger, unauthorized model.

Key Insights and Results

The framework was tested against CodeGPT, a state-of-the-art autocompletion model, using the POJ-104 dataset (52,000 C/C++ programs).

Protection Strength

When 40% of the training data was replaced with "unlearnable" versions, CodeGPT’s accuracy (Exact Match) dropped significantly. The model behaved as if it were trained on irrelevant, random data, effectively losing its ability to provide meaningful autocompletions for the protected tasks.

Performance degradation of CodeGPT (Exact Match - EM) when trained on unlearnable examples (UE) compared to baselines.

Readability and Functionality

  • Human Readability: Using the JPlag similarity tool, the transformed code maintained a 67.5% similarity to the original "clean" version. For comparison, two different programs solving the same problem typically share only 4.4% similarity.
  • Sacred Functionality: Unlike adversarial images that may lose quality, the transformed code maintains 100% functional parity. It introduces negligible performance overhead (<1%), as many statement-level changes are optimized away by standard compilers.

Conclusion

This research demonstrates that "scalpel-like" changes—which humans barely notice—are enough to derail deep learning models. While the current implementation focuses on C/C++, the concepts are transferable to other languages. As AI models continue to evolve, these "unlearnable examples" represent a critical step in the ongoing battle for data privacy and developer consent in the open-source ecosystem.

Summary updated

BibTeX
@inproceedings{ji2022unlearnable,
  author = {Zhenlan Ji and Pingchuan Ma and Shuai Wang},
  title = {{Unlearnable Examples: Protecting Open-Source Software from Unauthorized Neural Code Learning}},
  booktitle = {SEKE},
  year = {2022},
  doi = {10.18293/seke2022-066},
}
Figure