Table of Contents
Fetching ...

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

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

TL;DR

UniCoR tackles the problem of robust cross-language hybrid code retrieval by first diagnosing three core challenges through a large-scale empirical study. It then introduces a self-supervised framework with two modules: Multi-Perspective Supervised Contrastive Learning for deep semantic and modal alignment, and Representation Distribution Consistency Learning to achieve language-agnostic representations via MMD-based distribution alignment. Comprehensive experiments on multilingual benchmarks demonstrate that UniCoR outperforms strong baselines in both single-modal and hybrid retrieval and shows strong cross-language generalization, including unseen languages. The work provides a principled, model-agnostic training paradigm that enhances semantic understanding, modality collaboration, and language-agnosticity, with practical efficiency suitable for large-scale deployment.

Abstract

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 that learns Unified Code Representations framework designed to learn unified and robust code representations. 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 empirical benchmark and 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.

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

TL;DR

UniCoR tackles the problem of robust cross-language hybrid code retrieval by first diagnosing three core challenges through a large-scale empirical study. It then introduces a self-supervised framework with two modules: Multi-Perspective Supervised Contrastive Learning for deep semantic and modal alignment, and Representation Distribution Consistency Learning to achieve language-agnostic representations via MMD-based distribution alignment. Comprehensive experiments on multilingual benchmarks demonstrate that UniCoR outperforms strong baselines in both single-modal and hybrid retrieval and shows strong cross-language generalization, including unseen languages. The work provides a principled, model-agnostic training paradigm that enhances semantic understanding, modality collaboration, and language-agnosticity, with practical efficiency suitable for large-scale deployment.

Abstract

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 that learns Unified Code Representations framework designed to learn unified and robust code representations. 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 empirical benchmark and 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.

Paper Structure

This paper contains 25 sections, 5 equations, 4 figures, 8 tables.

Figures (4)

  • Figure 1: The overall framework of UniCoR. UniCoR first randomly selects a language pair, then uses various data augmentation methods to construct diverse positive sample pairs. MPCL is designed to learn a feature representation in which modal features interact fully. Finally, RDCL is designed to eliminate differences between the features of different language codes.
  • Figure 2: Model Comparison on Cross-Language Code Retrieval(MRR) .The colors transition from dark to bright yellow, representing the MRR scores from low to high.
  • Figure 3: The impact of different hyperparameters on Remix-based hybrid code retrieval
  • Figure 4: Case Study on Problem Retrieval via Hybrid Code Retrieval