← Latest papers
💬 NLP

Detecting Functional Memorization in Code Language Models

This paper introduces a counterfactual evaluation framework demonstrating that code language models can memorize functional logic beyond verbatim textual overlap, necessitating new auditing metrics that assess execution-based similarity rather than just text matching.

Original authors: Matthieu Meeus, Anil Ramakrishna, Matthew Grange, Zheng Xu, Luca Melis

Published 2026-06-12
📖 3 min read☕ Coffee break read

Original authors: Matthieu Meeus, Anil Ramakrishna, Matthew Grange, Zheng Xu, Luca Melis

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you have a giant library of computer code, like a massive cookbook filled with millions of recipes. You train a super-smart AI chef (a Large Language Model) to read every single page of this library so it can learn how to cook.

Now, imagine you ask this AI chef to write a new recipe for "Spicy Tofu."

The Old Way of Checking (Textual Similarity)
Previously, researchers checked if the AI was "cheating" (memorizing) by looking at the words. If the AI wrote a recipe that looked almost exactly like one in the library—using the same ingredients, the same sentence structure, and the same spelling—they said, "Aha! It memorized that recipe!"

But here's the problem: Two recipes can make the exact same delicious dish but look completely different on paper. One might say "add 2 cups of flour," while the other says "pour in 480ml of white powder." They are functionally identical (they make the same cake) but textually different.

The New Discovery (Functional Memorization)
This paper says: "We found that the AI chef is memorizing the logic of the recipes, not just the words."

Even when the AI changes the words, the variable names, and the sentence structure, it might still be secretly following the exact same secret steps from the library. It's like if the AI learned a secret formula for a specific company's "secret sauce" from the library. Even if it writes a new recipe that looks totally different, if it still uses that exact secret formula, it has leaked the company's trade secret.

How They Caught It (The Counterfactual Test)
To prove this, the researchers set up a clever experiment, like a "twin test":

  1. The "Experienced" Chef (Target Model): This AI was trained on the specific library containing the secret recipes.
  2. The "Naive" Chef (Reference Model): This AI is the exact same model, but it never saw those specific secret recipes. It only saw the general library.

They asked both chefs to write a recipe based on a simple prompt (like "Make a sauce for city X").

  • If the Naive Chef guessed a random, generic sauce, but the Experienced Chef wrote a sauce that used the exact same secret logic as the library (even with different words), they knew the Experienced Chef had memorized the logic.

The Results
The study found that while the "text-matching" detectors missed most of these cases, the "logic-matching" detectors caught them.

  • Text detectors said: "These recipes look different. No cheating."
  • Logic detectors said: "Wait, these recipes produce the exact same result using the exact same hidden steps. This is memorization!"

Why It Matters
The paper concludes that we can't just check if an AI is copying words. We have to check if it's copying the brain behind the code. If a company's proprietary trading algorithm or content moderation rules are in the training data, the AI might reproduce that secret logic in a new disguise, leaking sensitive information even if it doesn't copy a single word verbatim.

In a Nutshell:
The AI isn't just a photocopier; it's a mimic. It can learn the idea of a secret recipe and rewrite it in its own voice. The authors built new tools to catch the AI when it's doing this "logic mimicry," showing that current safety checks are too focused on spelling and grammar, missing the deeper, more dangerous kind of copying.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →