As large language models (LLMs) continue to advance, their code generation capabilities show significant promise in coding tasks. However, the detection of machine-generated code (MGC) remains crucial, particularly in educational settings where academ...
As large language models (LLMs) continue to advance, their code generation capabilities show significant promise in coding tasks. However, the detection of machine-generated code (MGC) remains crucial, particularly in educational settings where academic integrity and fairness are critical concerns. While most existing methods focus on document-level detection, users frequently copy partial code lines, stating the importance of line-level detection. To address this gap, we propose LiMO, a fine-grained MGC detection method that incorporates both line-level syntactic structure and coding stylistic information. We utilize a line-wise perplexity value derived from code generation models to capture syntactic features and introduce a coding convention feature that quantifies deviations from standard coding practices, such as Python’s PEP 8 standards. This hybrid approach enables more accurate MGC detection at both the document- and line-levels. To better reflect real-world scenarios where human and machine-generated code coexist, we introduce a new dataset, Human-Machine Generated Codes (HMGC). It is constructed using easy-to-access LLMs (GPT-3.5, GPT-4, and Gemini) and spans diverse languages (Python, Java, C++). Through comprehensive experiments, LiMO consistently and significantly outperforms all existing baselines, achieving the best performance across all evaluation metrics at both document- and line-levels.