一句话:提出 HedgeCode 两阶段框架,用对冲对比学习对齐代码与自然语言的表示空间,并结合多任务联合学习提升代码搜索效果。
代码搜索旨在根据自然语言查询检索正确的代码片段,现有深度学习方法虽改进了代码与描述的表征,但仍存在两个问题:一是代码与其自然语言描述表示空间之间的一致性缺乏保障,二是未能充分利用代码片段与描述之间的潜在相关性,难以区分相似代码片段的细粒度语义差异。为此,作者提出多任务对冲对比学习框架 HedgeCode,包含两个训练阶段:第一阶段为表示对齐阶段,采用对冲对比学习方法检测代码与自然语言文本之间的细微差异,并通过识别相关性对齐二者的表示空间;第二阶段为多任务联合学习,将前阶段训练好的模型作为编码器,结合监督对比学习与自监督对比学习任务对模型进行优化。该框架在 CodeSearchNet 基准上进行了评估,结果表明其能够缓解上述代码搜索中的局限,取得有效性能。
Code search is a vital activity in software engineering, focused on identifying and retrieving the correct code snippets based on a query provided in natural language. Approaches based on deep learning techniques have been increasingly adopted for this task, enhancing the initial representations of both code and its natural language descriptions. Despite this progress, there remains an unexplored gap in ensuring consistency between the representation spaces of code and its descriptions. Furthermore, existing methods have not fully leveraged the potential relevance between code snippets and their descriptions, presenting a challenge in discerning fine-grained semantic distinctions among similar code snippets. To address these challenges, we introduce a multi-task hedging contrastive Learning framework for Code Search, referred to as HedgeCode. HedgeCode is structured around two primary training phases. The first phase, known as the representation alignment stage, proposes a hedging contrastive learning approach. This method aims to detect subtle differences between code and natural language text, thereby aligning their representation spaces by identifying relevance. The subsequent phase involves multi-task joint learning, wherein the previously trained model serves as the encoder. This stage optimizes the model through a combination of supervised and self-supervised contrastive learning tasks. Our framework's effectiveness is demonstrated through its performance on the CodeSearchNet benchmark, showcasing HedgeCode's ability to address the mentioned limitations in code search tasks.
@inproceedings{paperbot8781,
title = {Hedgecode: A Multi-Task Hedging Contrastive Learning Framework for Code Search},
author = {Gong Chen and Xiaoyuan Xie and Daniel Tang and Qi Xin and Wenjie Liu},
booktitle = {ICSE},
year = {2025},
doi = {10.1109/icse55347.2025.00008}
}