An Empirical Study on Automatically Detecting AI-Generated Source Code: How Far Are We?

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Suh, Hyunjae, Tafreshipour, Mahan, Li, Jiawei, Bhattiprolu, Adithya, Ahmed, Iftekhar
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866917829819760640
author Suh, Hyunjae
Tafreshipour, Mahan
Li, Jiawei
Bhattiprolu, Adithya
Ahmed, Iftekhar
author_facet Suh, Hyunjae
Tafreshipour, Mahan
Li, Jiawei
Bhattiprolu, Adithya
Ahmed, Iftekhar
contents Artificial Intelligence (AI) techniques, especially Large Language Models (LLMs), have started gaining popularity among researchers and software developers for generating source code. However, LLMs have been shown to generate code with quality issues and also incurred copyright/licensing infringements. Therefore, detecting whether a piece of source code is written by humans or AI has become necessary. This study first presents an empirical analysis to investigate the effectiveness of the existing AI detection tools in detecting AI-generated code. The results show that they all perform poorly and lack sufficient generalizability to be practically deployed. Then, to improve the performance of AI-generated code detection, we propose a range of approaches, including fine-tuning the LLMs and machine learning-based classification with static code metrics or code embedding generated from Abstract Syntax Tree (AST). Our best model outperforms state-of-the-art AI-generated code detector (GPTSniffer) and achieves an F1 score of 82.55. We also conduct an ablation study on our best-performing model to investigate the impact of different source code features on its performance.
format Preprint
id arxiv_https___arxiv_org_abs_2411_04299
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle An Empirical Study on Automatically Detecting AI-Generated Source Code: How Far Are We?
Suh, Hyunjae
Tafreshipour, Mahan
Li, Jiawei
Bhattiprolu, Adithya
Ahmed, Iftekhar
Software Engineering
Artificial Intelligence (AI) techniques, especially Large Language Models (LLMs), have started gaining popularity among researchers and software developers for generating source code. However, LLMs have been shown to generate code with quality issues and also incurred copyright/licensing infringements. Therefore, detecting whether a piece of source code is written by humans or AI has become necessary. This study first presents an empirical analysis to investigate the effectiveness of the existing AI detection tools in detecting AI-generated code. The results show that they all perform poorly and lack sufficient generalizability to be practically deployed. Then, to improve the performance of AI-generated code detection, we propose a range of approaches, including fine-tuning the LLMs and machine learning-based classification with static code metrics or code embedding generated from Abstract Syntax Tree (AST). Our best model outperforms state-of-the-art AI-generated code detector (GPTSniffer) and achieves an F1 score of 82.55. We also conduct an ablation study on our best-performing model to investigate the impact of different source code features on its performance.
title An Empirical Study on Automatically Detecting AI-Generated Source Code: How Far Are We?
topic Software Engineering
url https://arxiv.org/abs/2411.04299