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

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[Formula: see text] 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.

Authors

Institutions

Publication Details

Journal
International Journal of Software Engineering and Knowledge Engineering
Published
2025-09-04
DOI
https://doi.org/10.1142/s0218194025500524
Primary Topic
Digital Media Forensic Detection
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

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

Guohua Shen, Zhiqiu Huang, Yaoshen Yu, Yu Zhao et al.
International Journal of Software Engineering and Knowledge Engineering
Digital Media Forensic Detection
article

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

Guohua Shen, Zhiqiu Huang, Yaoshen Yu, Yu Zhao, J. L. Fu
article en

Abstract

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[Formula: see text] 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.

International Journal of Software Engineering and Knowledge EngineeringVol. 35(12)
Nanjing University of Aeronautics and Astronautics (CN)
Openalex Percentile: Top 77%
Digital Media Forensic Detection
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

LevDetectCode: Zero-Shot Detection of AI-Generated Code Using Levenshtein Distance — Guohua Shen, Zhiqiu Huang, et al. · International Journal of Software Engineering and Knowledge Engineering (2025) | TGRS Research Map | TGRS