Abstract
The ubiquitous adoption of Large Language Generation Models (LLMs) in programming has underscored the importance of differentiating between human-written code and code generated by intelligent models. This paper specifically aims to distinguish code generated by ChatGPT from that authored by humans. Our investigation reveals disparities in programming style, technical level, and readability between these two sources. Consequently, we develop a discriminative feature set for differentiation and evaluate its efficacy through ablation experiments. Additionally, we devise a dataset cleansing technique, which employs temporal and spatial segmentation, to mitigate the dearth of datasets and to secure high-caliber, uncontaminated datasets. To further enrich data resources, we employ "code transformation," "feature transformation," and "feature customization" techniques, generating an extensive dataset comprising 10,000 lines of ChatGPT-generated code. The salient contributions of our research include: proposing a discriminative feature set yielding high accuracy in differentiating ChatGPT-generated code from human-authored code in binary classification tasks; devising methods for generating extensive ChatGPT-generated codes; and introducing a dataset cleansing strategy that extracts immaculate, high-grade code datasets from open-source repositories, thus achieving exceptional accuracy in code authorship attribution tasks.
Introduction
The rapid rise of Large Language Models (LLMs) like ChatGPT has transformed the landscape of software development. While these tools offer unprecedented productivity gains, they have also introduced a "provenance crisis." Identifying the origin of code is now critical for security auditing, copyright enforcement, and academic integrity. Platforms like Stack Overflow have struggled with a flood of low-quality AI responses, and educational institutions face challenges in assessing student work fairly.
Traditional code authorship attribution tools were designed to distinguish between different human styles, not to separate human effort from machine generation. This research bridges that gap by identifying the specific stylistic and technical markers—the "fingerprints"—that separate human "messiness" from AI "standardization."
Methodology
The study approaches the problem as a binary classification task. The methodology is built upon three core pillars:
1. Feature Engineering
The researchers developed a comprehensive discriminative feature set categorized into three domains:
- Lexical Features: Analysis of comments, strings, identifiers, and library usage patterns.
- Structural Layout: Measurement of indentation length, average nesting depth, and the ratio of blank lines.
- Semantic Features: Evaluation of "runnability," logical correctness, and time-space performance metrics.
2. Dataset Construction and Cleansing
To ensure a high-quality, "uncontaminated" dataset, the team applied a novel temporal and spatial segmentation technique to GitHub data. By focusing on code from 2021–2022 (temporal), they ensured the code was modern but less likely to have been included in the LLM's initial training set. Spatial filtering removed organization accounts and forked repositories to isolate individual human styles.
For the AI component, the team generated 10,000 lines of code using three strategies: code translation (porting between languages), functional translation (rewriting based on descriptions), and custom functionality (solving textbook or competition problems from scratch).
Key Insights: The AI Fingerprint
The research identified several "aha moments" where human and AI coding styles diverge significantly. ChatGPT-generated code tends to be "too perfect," adhering strictly to conventional formatting and coding standards. In contrast, human code often contains "scars" of the iterative development process, such as commented-out snippets, unused variables, or debugging statements.
As shown in the token frequency analysis above, humans and GPT models utilize comments and string tokens with markedly different frequencies. GPT models often exhibit a higher frequency of semantically rich, descriptive tokens, while human code shows more variance and reliance on specific shorthand or "development remnants."
Experimental Results
The classification models consistently achieved high performance across both Java and C++ datasets. The researchers tested several algorithms, including Random Forest, Sequential Minimal Optimization (SMO), Simple Logistic, and J48.
As illustrated in the accuracy comparison, the J48 algorithm reached a peak accuracy of 97.8% in Java when utilizing the full feature set. Ablation studies confirmed that while lexical features are strong indicators on their own, the synergy between lexical and structural layout features provides the most robust detection capabilities.
Conclusion and Future Work
While the current methodology achieves over 90% accuracy, the field remains a "cat-and-mouse" game. The researchers acknowledge limitations regarding prompt sensitivity; if a user specifically instructs an LLM to "write messy code," detection may become more difficult. Future work will focus on expanding dataset diversity and exploring the stylistic fingerprints of other emerging models like Claude or Llama, as well as specialized code generation tools like GitHub Copilot.
Summary updated