arrow
Return

LevDetectCode: Zero-Shot Detection of AI-Generated Code using Levenshtein Distance

delete2025-09-01
delete0
PRE
AI
J
J. L. Fu
沈
沈国华 (Guohua Shen) *
黄
黄志球 (Zhiqiu Huang)
Y
Yaoshen Yu
Y
Yu Zhao
DOI:10.1142/S0218194025500524delete
deleteOriginal
deleteOriginal request for help
deleteShare
deleteSave
Abstract

Abstract

En 中文
AI-generated code is spreading rapidly, making it harder to trace the true origins of code. Text-based tools such as DetectGPT perform well on texts but struggle with code. We propose a new approach: under masked reconstruction, code produced by LLMs exhibits a much wider spread in Levenshtein distance than human-written code. Our key innovation is to treat this Levenshtein distance dispersion as an indicator for token-probability differences, leading us to develop LevDetectCode. Our zero-shot detector relies solely on string-level Levenshtein distance, requiring neither GPUs nor access to model internals. Experiments on Python snippets from MBPP-train and HumanEval, as well as Java data from CodeContest_Java_test, using GPT-3.5, GPT-4, and Deepseek-V3, show a 5-10 point AUROC improvement over other zero-shot baselines, with an additional case study for the C++ dataset, which also demonstrates strong effectiveness. Furthermore, it runs nearly 3000 times faster and significantly reduces memory usage. These results demonstrate that Levenshtein distance can outperform other zero-shot methods that rely on model-based computations, offering a practical and portable solution for detecting AI-generated code.
Keywords:
Large language models
zero-shot
AI-generated code
Levenshtein distance
GPT-4
Deepseek-V3

Journal

I
International Journal of Software Engineering and Knowledge Engineering
IF:
0.6
Papers:
107
Citations:
543

Organization

No organization information available
Cited Papers

Cited Papers

Mann‐Whitney U Test
err2010-01-30
err0
PREAI
errPatrick E. McKnight; Julius Najab
errShare
errSave
Competition-level code generation with AlphaCode
err2022-12-09
err0
errOAAI
errYujia Li; David Choi; Junyoung Chung; Nate Kushman; Julian Schrittwieser; Rémi Leblond; Tom Eccles; James Keeling; Felix Gimeno; Agustin Dal Lago; Thomas Hubert; Peter Choy; Cyprien de Masson d’Autume; Igor Babuschkin; Xinyun Chen; Po-Sen Huang; Johannes Welbl; Sven Gowal; Alexey Cherepanov; James Molloy; Daniel J. Mankowitz; Esme Sutherland Robson; Pushmeet Kohli; Nando de Freitas; Koray Kavukcuoglu; Oriol Vinyals
errShare
errSave
Assessing AI Detectors in Identifying AI-Generated Code: Implications for Education
err2024-05-24
err0
errOAAI
errWei 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
errShare
errSave
Effect Size Estimates: Current Use, Calculations, and Interpretation
err2012-01-01
err2.7K
PREAI
errFritz, Catherine O.; Morris, Peter E.; Richler, Jennifer J.
errShare
errSave
Detecting ChatGPT-Generated Code Submissions in a CS1 Course Using Machine Learning Models
err2024-03-07
err0
PREAI
errMuntasir Hoq; Yang Shi; Juho Leinonen; Damilola Babalola; Collin Lynch; Thomas Price; Bita Akram
errShare
errSave
no more