← Latest papers
💬 NLP

Fine-Tuning Pre-Trained Code Models for AI-Generated Code Detection

The paper presents the "Archaeology" team's system for SemEval-2026 Task 13, which leverages fine-tuned pre-trained code models and specialized strategies like leave-one-language-out cross-validation and sandwich token packing to achieve top-tier performance in detecting AI-generated code and attributing its source.

Original authors: Jany-Gabriel Ispas, Sergiu Nisioi

Published 2026-05-05
📖 5 min read🧠 Deep dive

Original authors: Jany-Gabriel Ispas, Sergiu Nisioi

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 a digital detective agency called Archaeology. Their job isn't to dig up ancient pottery, but to sift through piles of computer code to answer two big questions:

  1. Who wrote this? Was it a human programmer or a robot (AI)?
  2. Which robot wrote it? If it was a robot, which specific AI model created it?

This team entered a high-stakes competition called SemEval-2026 Task 13 to prove their skills. Here is how they did it, explained simply.

The Challenge: A Two-Part Mystery

The competition had two distinct puzzles, each requiring a different detective strategy.

Puzzle A: The "Human vs. Robot" Test (Binary Classification)

  • The Goal: Look at a piece of code and say, "Human" or "AI."
  • The Trap: The team was trained mostly on Python code (91% of their practice data), but the final test included languages they had never seen before, like JavaScript, Go, and C#. It's like teaching a chef to cook only Italian food, then asking them to identify if a dish is homemade or factory-made when it's actually a Thai curry.
  • The Clue: AI code tends to be longer and more uniform, while human code is shorter and more chaotic. However, this rule flips depending on the language (e.g., in C++, humans actually write longer code than AI).

Puzzle B: The "Which Robot?" Test (Multi-Class Attribution)

  • The Goal: If the code is AI-generated, identify exactly which of the 11 different AI models wrote it.
  • The Trap: The data was wildly unbalanced. One category (Human-written code) made up 88% of the data, while some specific AI models had fewer than 2,000 examples. It's like trying to find a needle in a haystack, where the haystack is 99% hay and the needles are different colors, but you only have one red needle and a million blue ones.
  • The Clue: Different AI models have subtle "handwriting" styles, but these styles are hard to spot in long, complex code.

The Detective's Toolkit

The team didn't just guess; they used four different "super-eyes" (pre-trained AI models) and gave them special training techniques for each puzzle.

For Puzzle A (Human vs. Robot)

  1. The "Language Swap" Drill: To prepare for the surprise languages in the test, they trained the models by hiding one language at a time. They taught the model to recognize patterns without relying on specific language tricks (like how Python uses # for comments).
  2. The "Scrub and Mask" Workout: They stripped away comments and replaced numbers with placeholders during training. This forced the models to look at the logic of the code, not just the surface decorations.
  3. The "Chunking" Strategy: Since the test code was often too long to read in one go, they sliced it into overlapping pieces (like reading a long book by reading a few pages at a time). They then took the average of these slices, ignoring the most extreme "noisy" guesses, to make a final decision.
  4. The "Difficult Case" Calibration: They created a special "hard test" using examples that a simple computer program got wrong. They tuned their decision threshold (the line between "Human" and "AI") based on these tricky cases to ensure they didn't get fooled by the test data.

For Puzzle B (Which Robot?)

  1. The "Sandwich" Technique: Since the code was too long to fit in the model's memory, they didn't just chop off the middle. Instead, they kept the Head (start) and the Tail (end) of the code and stuffed them together like a sandwich, with a special marker in the middle. This preserved the style at the beginning and end, which is often where the "robot signature" hides.
  2. The "Fairness" Weight: Because some AI models were rare in the data, the team told the model, "Don't just guess the most common one! Pay extra attention to the rare ones." They adjusted the scoring system so the model learned to spot the rare robots, not just the popular ones.
  3. The "Crowd Wisdom" Vote: They ran the same code through the model multiple times with slight variations and let the models vote on the answer. This reduced errors and increased confidence.

The Results

The "Archaeology" team did very well:

  • Puzzle A: They got a score of 0.737, placing them 6th out of 81 teams. Their best tool was CodeBERT, which seemed to understand the "logic" of code better than the others.
  • Puzzle B: They got a score of 0.422, placing them 7th out of 34 teams. Their best tool here was UniXcoder, which benefited from looking at longer chunks of code and using the "voting" strategy.

The Big Takeaway

The team discovered that how a model was trained matters more than how big it is.

  • The smaller models (125 million parameters) that were trained specifically to understand code logic performed better at spotting AI.
  • The giant model (220 million parameters) didn't win, suggesting that for this specific job, being a "specialist" is better than being a "generalist."

In short, the team proved that with the right training tricks—like slicing long code, ignoring surface noise, and voting on answers—you can build a system that is surprisingly good at catching AI-generated code, even when it tries to disguise itself in new languages.

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 →