arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2512.10452cs.SE
收藏

UniCoR: 代码多模态协作以实现稳健的跨语言混合代码检索

UniCoR: Modality Collaboration for Robust Cross-Language Hybrid Code Retrieval

Central South University(中南大学);Harbin Institute of Technology(哈尔滨工业大学);Zhejiang University(浙江大学);Hangzhou Dianzi University(杭州电子科技大学);Singapore Management University(新加坡管理大学)

Yang Yang, Li Kuang, Jiakun Liu, Zhongxin Liu, Yingjie Xia, David Lo

AI总结:

UniCoR通过多模态协作和自监督学习提升跨语言混合代码检索的语义理解和泛化能力。

摘要:

有效的代码检索至关重要,已成为使用自然语言和代码片段进行混合模式代码搜索的重要范式。然而,现有方法是否能有效利用此类混合查询,尤其是在跨语言背景下仍不明确。我们对代表性代码模型进行了全面的经验研究,揭示了三个挑战:(1)语义理解不足;(2)混合代码检索中的融合效率低下;(3)跨语言场景下的泛化能力弱。为解决这些挑战,我们提出了UniCoR,一种新的自监督框架,旨在学习语义稳健、多模态协作且语言无关的统一代码表示。首先,我们设计了一个多视角监督对比学习模块,以增强语义理解和多模态融合。它对代码到代码、自然语言到代码以及自然语言到自然语言的表示进行对齐,迫使模型捕捉模态间的语义本质。其次,我们引入了表示分布一致性学习模块以提高跨语言泛化能力,该模块明确对齐不同编程语言的特征分布,实现语言无关的表示学习。在经验基准和大规模基准上的广泛实验表明,UniCoR优于所有基线模型,平均在MRR上提高8.64%,在MAP上提高11.54%。此外,UniCoR在混合代码检索中表现出稳定性,并在跨语言场景中展现出良好的泛化能力。

英文摘要:

Effective code retrieval is indispensable and it has become an important paradigm to search code in hybrid mode using both natural language and code snippets. Nevertheless, it remains unclear whether existing approaches can effectively leverage such hybrid queries, particularly in cross-language contexts. We conduct a comprehensive empirical study of representative code models and reveal three challenges: (1)insufficient semantic understanding; (2) inefficient fusion in hybrid code retrieval; and (3) weak generalization in cross-language scenarios. To address these challenges, we propose UniCoR, a novel self-supervised framework designed to learn Unified Code Representations that are semantically robust, modally collaborative, and language-agnostic. Firstly, we design a multi-perspective supervised contrastive learning module to enhance semantic understanding and modality fusion. It aligns representations from multiple perspectives, including code-to-code, natural language-to-code, and natural language-to-natural language, enforcing the model to capture a semantic essence among modalities. Secondly, we introduce a representation distribution consistency learning module to improve cross-language generalization, which explicitly aligns the feature distributions of different programming languages, enabling language-agnostic representation learning. Extensive experiments on both an empirical benchmark and a large-scale benchmark show that UniCoR outperforms all baseline models, achieving an average improvement of 8.64% in MRR and 11.54% in MAP over the best-performing baseline. Furthermore, UniCoR exhibits stability in hybrid code retrieval and generalization capability in cross-language scenarios.

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

↑