Investigating the Efficacy of Large Language Models for Code Clone Detection
作者: Mohamad Khajezade, Jie JW Wu, Fatemeh Hendijani Fard, Gema Rodríguez-Pérez, Mohamed Sami Shehata
分类: cs.SE, cs.AI, cs.CL, cs.LG
发布日期: 2024-01-24 (更新: 2024-01-30)
💡 一句话要点
探讨大语言模型在代码克隆检测中的有效性
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 代码克隆检测 大语言模型 自然语言处理 软件工程 机器学习 零样本学习 跨语言应用
📋 核心要点
- 现有研究主要集中在生成性任务上,缺乏对非生成性任务如代码克隆检测的深入探讨。
- 本研究通过构建CCD数据集,探索大语言模型在代码克隆检测中的应用,采用零样本设置进行实验。
- 实验结果显示,ChatGPT在跨语言和单语代码克隆检测中均表现优异,超越了基线模型,提供了新的研究方向。
📝 摘要(中文)
大语言模型(LLMs)在自然语言处理和软件工程任务中表现出色,尤其是在代码生成等生成性任务中。然而,针对非生成性任务如代码克隆检测(CCD)的研究相对较少。本研究通过构建单语和跨语的CCD数据集,利用ChatGPT在零样本设置下检测Java和Ruby代码对中的Type-4代码克隆。结果表明,ChatGPT在跨语言CCD中取得了0.877的F1分数,且在单语CCD中表现与完全微调模型相当,F1分数为0.878。此外,提示和问题难度对ChatGPT的性能有显著影响。最后,研究提供了初步分析的见解和未来方向。
🔬 方法详解
问题定义:本研究旨在解决大语言模型在代码克隆检测(CCD)中的应用问题,现有方法在非生成性任务上效果有限,缺乏有效的研究和应用。
核心思路:通过构建单语和跨语的CCD数据集,利用ChatGPT在零样本设置下进行代码克隆检测,探索其在非生成性任务中的有效性。
技术框架:整体流程包括数据集构建、提示设计、模型训练与评估。首先从CodeNet构建数据集,然后设计不同的提示以引导ChatGPT进行检测,最后评估其性能。
关键创新:本研究的创新点在于首次将大语言模型应用于非生成性任务的代码克隆检测,展示了其在此领域的潜力和有效性。
关键设计:在实验中,采用了不同的提示设计和问题难度设置,优化了模型的输入,确保了检测的准确性和有效性。
🖼️ 关键图片
📊 实验亮点
实验结果显示,ChatGPT在跨语言代码克隆检测中获得了0.877的F1分数,超越了基线模型;在单语代码克隆检测中,F1分数为0.878,表现与完全微调模型相当。这表明大语言模型在非生成性任务中的应用潜力。
🎯 应用场景
该研究的潜在应用领域包括软件开发、代码审查和自动化测试等。通过提高代码克隆检测的效率和准确性,可以帮助开发者更好地维护和优化代码库,降低技术债务。此外,研究结果为未来大语言模型在其他非生成性任务中的应用提供了参考。
📄 摘要(原文)
Large Language Models (LLMs) have demonstrated remarkable success in various natural language processing and software engineering tasks, such as code generation. The LLMs are mainly utilized in the prompt-based zero/few-shot paradigm to guide the model in accomplishing the task. GPT-based models are one of the popular ones studied for tasks such as code comment generation or test generation. These tasks are
generative' tasks. However, there is limited research on the usage of LLMs fornon-generative' tasks such as classification using the prompt-based paradigm. In this preliminary exploratory study, we investigated the applicability of LLMs for Code Clone Detection (CCD), a non-generative task. By building a mono-lingual and cross-lingual CCD dataset derived from CodeNet, we first investigated two different prompts using ChatGPT to detect Type-4 code clones in Java-Java and Java-Ruby pairs in a zero-shot setting. We then conducted an analysis to understand the strengths and weaknesses of ChatGPT in CCD. ChatGPT surpasses the baselines in cross-language CCD attaining an F1-score of 0.877 and achieves comparable performance to fully fine-tuned models for mono-lingual CCD, with an F1-score of 0.878. Also, the prompt and the difficulty level of the problems has an impact on the performance of ChatGPT. Finally we provide insights and future directions based on our initial analysis