Artificial intelligence (AI) assistants such as GitHub Copilot and ChatGPT, built on large language models like GPT-4, are revolutionizing how programming tasks are performed, raising questions about whether code is authored by generative AI models. Such questions are of particular interest to educators, who worry that these tools enable a new form of academic dishonesty, in which students submit AI generated code as their own work. Our research explores the viability of using code stylometry and machine learning to distinguish between GPT-4 generated and human-authored code. Our dataset comprises human-authored solutions from CodeChef and AI-authored solutions generated by GPT-4. Our classifier outperforms baselines, with an F1-score and AUC-ROC score of 0.91. A variant of our classifier that excludes gameable features (e.g., empty lines, whitespace) still performs well with an F1-score and AUC-ROC score of 0.89. We also evaluated our classifier with respect to the difficulty of the programming problem and found that there was almost no difference between easier and intermediate problems, and the classifier performed only slightly worse on harder problems. Our study shows that code stylometry is a promising approach for distinguishing between GPT-4 generated code and human-authored code.
翻译:人工智能辅助工具(如基于GPT-4等大语言模型构建的GitHub Copilot和ChatGPT)正在彻底改变编程任务的执行方式,这引发了关于代码是否由生成式AI模型编写的疑问。此类问题尤其受到教育工作者关注,他们担忧这些工具会催生新型学术不端行为——学生将AI生成的代码作为自身成果提交。本研究探讨了利用代码风格计量学与机器学习区分GPT-4生成代码与人类编写代码的可行性。我们的数据集包含来自CodeChef的人工编写解决方案与GPT-4生成的AI编写解决方案。分类器在F1分数和AUC-ROC评分上均以0.91的表现超越基线模型。排除可操纵特征(如空行、空白符)的分类器变体仍表现优异,F1分数和AUC-ROC评分达0.89。我们同时评估了分类器在不同编程问题难度下的表现,发现简单题与中等难度题的结果几乎无差异,仅在难题上性能略有下降。研究表明,代码风格计量学是区分GPT-4生成代码与人类编写代码的有效方法。