arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.12326cs.SEcs.AI
收藏

在解码器-only模型中通过对比学习实现更好的代码理解

Towards Better Code Understanding in Decoder-Only Models with Contrastive Learning

Jiayi Lin, Yanlin Wang, Yibiao Yang, Lei Zhang, Yutao Xie

AI总结:

本文提出CL4D框架,通过对比学习提升解码器-only模型的代码表示能力,在代码搜索和克隆检测任务中取得优异性能。

摘要:

近年来,大规模代码生成模型的进展在生成高质量代码方面取得了显著进步。这些模型通过自监督的方式在大量未标记的代码语料库上训练,使用解码器-only架构。然而,尽管这些解码器-only模型在生成方面表现强大,但在代码理解任务如代码搜索和克隆检测上往往表现有限,主要归因于其生成导向的训练目标。虽然从头开始训练大规模编码器-only模型可以在大规模代码数据集上提高理解能力,但这种方法计算成本高且耗时。在本文中,我们探索了一种更高效的方法,通过将预训练的解码器-only代码生成模型的知识转移到代码理解任务中。我们研究了解码器-only架构如何有效适应以学习具有辨别性和语义意义的代码表示。为此,我们提出了CL4D,一种针对增强解码器-only模型表示能力而设计的对比学习框架。在多个基准数据集上的广泛实验表明,CL4D在代表性的代码理解任务上,如代码搜索和克隆检测,实现了与现有方法相当或更优的性能。进一步分析显示,CL4D通过减少语义相似代码片段之间的距离,显著提高了代码表示的语义对齐。这些发现突显了利用解码器-only模型作为代码生成和理解统一骨干的可行性。

英文摘要:

Recent advances in large-scale code generation models have led to remarkable progress in producing high-quality code. These models are trained in a self-supervised manner on extensive unlabeled code corpora using a decoder-only architecture. However, despite their generative strength, decoder-only models often exhibit limited performance on code understanding tasks such as code search and clone detection, primarily due to their generation-oriented training objectives. While training large encoder-only models from scratch on massive code datasets can improve understanding ability but remains computationally expensive and time-consuming. In this paper, we explore a more efficient alternative by transferring knowledge from pre-trained decoder-only code generation models to code understanding tasks. We investigate how decoder-only architectures can be effectively adapted to learn discriminative and semantically meaningful code representations. To this end, we propose CL4D, a contrastive learning framework tailored to strengthen the representation capabilities of decoder-only models. Extensive experiments on multiple benchmark datasets demonstrate that CL4D achieves competitive or superior performance compared to existing methods on representative code understanding tasks, including code search and clone detection. Further analysis reveals that CL4D substantially improves the semantic alignment of code representations by reducing the distance between semantically similar code snippets. These findings highlight the feasibility of leveraging decoder-only models as a unified backbone for both code generation and understanding.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑