Assessing AI Detectors in Identifying AI-Generated Code: Implications for Education

Wei Hung Pan, Ming Jie Chok, Jonathan Leong Shan Wong, Yung Xin Shin, Yeong Shian Poon, Zhou Yang, Chun Yong Chong, David Lo, Mei Kuan Lim

TL;DR

Current AI content detectors are remarkably bad at identifying AI-generated code, often performing no better than a coin flip. By testing five popular detectors against 13 different code-generation strategies, researchers found that these tools—originally designed for natural language—struggle with the rigid syntax of programming, making them unreliable for enforcing academic integrity in computer science education.

What Problem Does This Paper Address?

As Large Language Models (LLMs) like ChatGPT become ubiquitous, educators in Software Engineering (SE) and Computer Science (CS) face a dilemma: how do they ensure students are actually learning to code rather than just prompting an AI?

While several Artificial Intelligence Generated Content (AIGC) detectors exist, most were trained on natural language (English prose). Programming code is a different beast entirely—it follows strict structural rules and lacks the linguistic "flow" or "perplexity" found in human writing. This paper investigates whether these off-the-shelf detectors can actually distinguish between a human-written Python script and one generated by an LLM, especially when students use clever prompting to bypass detection.

Methods

The researchers developed a workflow called DynCodeMetrics to systematically evaluate five prominent AIGC detectors: GPTZero, Sapling, GPT-2 Detector, DetectGPT, and GLTR.

The core of their approach was the creation of 13 prompt variants. Instead of just asking ChatGPT for a solution, they simulated various student behaviors, such as:

  • Prompt Engineering: Asking the AI to "mimic a human response" or "remove all comments."
  • Code Obfuscation: Using scripts to automatically replace variable/function names with single letters (e.g., x, y, z) or injecting "dead code" (useless snippets) to act as noise.
  • Structural Changes: Requesting "long method" vs. "short method" versions of the same logic.

By comparing how detectors handled these variants versus original human-written solutions, the team could identify exactly where the detection logic breaks down.

Datasets

The study utilized a dataset of 5,069 unique coding problems and their corresponding human-written Python solutions. These were sourced from:

  • Kaggle: 3,264 samples.
  • LeetCode: 1,725 samples.
  • Quescol: 80 samples.

From this base, they generated 13 sets of AI-generated counterparts using ChatGPT, resulting in a massive evaluation pool of over 70,000 code samples.

Key Insights and Ideas

  • The "Text-First" Bias: Most detectors look for linguistic patterns (like "burstiness" or "perplexity"). Because code is naturally repetitive and structured, detectors often misclassify all code as human-written simply because it doesn't look like the "smooth" text typical of LLM prose.
  • The Obfuscation Paradox: Interestingly, some detectors like GLTR actually became more accurate when the code was "messier" (e.g., adding dead code or removing comments). This suggests these tools are sensitive to the distribution of tokens; when the code looks less like a "perfect" textbook example, the detector's statistical model reacts more strongly.
  • Defaulting to "Human": GPT-2 Detector and GPTZero showed a heavy bias toward labeling samples as "Human." While this prevents false accusations of cheating, it makes them nearly useless for actually catching AI usage, as their True Negative Rate (identifying AI as AI) was abysmal.
  • Sapling's Edge: Among the tools tested, Sapling was the most consistent, often achieving accuracy scores above 0.6. However, even this is far below the threshold required for high-stakes academic disciplinary actions.

Key Results

  • Accuracy Floor: Both the GPT-2 Detector and GPTZero hovered around 0.5 accuracy, effectively performing at random chance.
  • DetectGPT's Struggle: This detector frequently misclassified human code as AI-generated, which is a "worst-case scenario" for educators who might falsely accuse a student.
  • GLTR Sensitivity: GLTR showed the highest variance. Its accuracy jumped from 0.48 (Variant 3) to 0.76 (Variant 7), proving that how a student prompts the AI significantly changes their "detectability."
  • The Bottom Line: The researchers conclude that existing AIGC detectors perform poorly in distinguishing human vs. AI code, and their inherent weaknesses make them easy to bypass with simple prompt tweaks.

Limitations and Future Work

The authors acknowledge several limitations:

  1. Language Scope: The study focused exclusively on Python. Other languages with different syntax (like C++ or Haskell) might yield different results.
  2. LLM Specificity: The AI code was generated solely by ChatGPT. Results might differ for code-specific models like GitHub Copilot or StarCoder.
  3. Non-Determinism: LLMs can produce different outputs for the same prompt, which can introduce slight inconsistencies in the dataset.

Future Work: The authors call for the development of specialized, code-centric detectors that understand AST (Abstract Syntax Tree) structures rather than just treating code as "text." They also suggest that educators should focus on "AI-resilient" assessment designs—like oral exams or in-class coding—rather than relying on flawed automated detection tools.

Summary updated

Abstract

Educators are increasingly concerned about the usage of Large Language Models (LLMs) such as ChatGPT in programming education, particularly regarding the potential exploitation of imperfections in Artificial Intelligence Generated Content (AIGC) Detectors for academic misconduct. In this paper, we present an empirical study where the LLM is examined for its attempts to bypass detection by AIGC Detectors. This is achieved by generating code in response to a given question using different variants. We collected a dataset comprising 5,069 samples, with each sample consisting of a textual description of a coding problem and its corresponding human-written Python solution codes. These samples were obtained from various sources, including 80 from Quescol, 3,264 from Kaggle, and 1,725 from LeetCode. From the dataset, we created 13 sets of code problem variant prompts, which were used to instruct ChatGPT to generate the outputs. Subsequently, we assessed the performance of five AIGC detectors. Our results demonstrate that existing AIGC Detectors perform poorly in distinguishing between human-written code and AI-generated code.
BibTeX
@inproceedings{pan2024assessing,
  author = {Wei Hung Pan and Ming Jie Chok and Jonathan Leong Shan Wong and Yung Xin Shin and Yeong Shian Poon and Zhou Yang and Chun Yong Chong and David Lo and Mei Kuan Lim},
  title = {{Assessing AI Detectors in Identifying AI-Generated Code: Implications for Education}},
  booktitle = {SEET@ICSE},
  year = {2024},
  doi = {10.1145/3639474.3640068},
}

Loading related content...

Figure