arXiv:2504.07740cs.SEcs.CL2025-04被引 8

无需微调的零样本跨域代码搜索,性能超越现有方法

Zero-Shot Cross-Domain Code Search without Fine-Tuning

  • 将代码搜索拆解为查询-注释、代码-代码匹配,提升跨域泛化能力
  • 在三个数据集上平均比CoCoSoDa和UniXcoder高21.4%和24.9%的MRR
  • 无需微调,适合资源有限但需跨领域检索的开发者

代码搜索旨在为自然语言查询检索语义相关的代码片段。尽管预训练语言模型(PLMs)在此任务上表现优异,但在跨域场景下仍面临性能下降或需昂贵微调的问题。目前唯一有效的零样本跨域代码搜索方法RAPID依赖大量计算资源进行微调,且需为每个领域维护专用模型。本文提出一种无需微调的零样本跨域代码搜索方法CodeBridge。通过将查询-代码匹配分解为更简单的查询-注释匹配与代码-代码匹配任务,利用大语言模型生成注释与伪代码,并基于PLM相似度评分与采样融合策略整合三类匹配。实验表明,该方法在三个数据集上平均比CoCoSoDa和UniXcoder分别高出21.4%和24.9%的MRR,效果优于或相当于需要微调的RAPID方法。

原文摘要 · Abstract (English)

Code search aims to retrieve semantically relevant code snippets for natural language queries. While pre-trained language models (PLMs) have shown remarkable performance in this task, they struggle in cross-domain scenarios, often requiring costly fine-tuning or facing performance drops in zero-shot settings. RAPID, which generates synthetic data for model fine-tuning, is currently the only effective method for zero-shot cross-domain code search. Despite its effectiveness, RAPID demands substantial computational resources for fine-tuning and needs to maintain specialized models for each domain, underscoring the need for a zero-shot, fine-tuning-free approach for cross-domain code search. The key to tackling zero-shot cross-domain code search lies in bridging the gaps among domains. In this work, we propose to break the query-code matching process of code search into two simpler tasks: query-comment matching and code-code matching. Our empirical study reveals the strong complementarity among the three matching schemas in zero-shot cross-domain settings, i.e., query-code, query-comment, and code-code matching. Based on the findings, we propose CodeBridge, a zero-shot, fine-tuning-free approach for cross-domain code search. Specifically, CodeBridge uses Large Language Models (LLMs) to generate comments and pseudo-code, then combines query-code, query-comment, and code-code matching via PLM-based similarity scoring and sampling-based fusion. Experimental results show that our approach outperforms the state-of-the-art PLM-based code search approaches, i.e., CoCoSoDa and UniXcoder, by an average of 21.4% and 24.9% in MRR, respectively, across three datasets. Our approach also yields results that are better than or comparable to those of the zero-shot cross-domain code search approach RAPID, which requires costly fine-tuning.

代码搜索零样本跨域LLM

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。