arXiv:2508.00546cs.SEcs.AI2025-08被引 6

用自适应蒸馏提升代码检索效率,兼顾精度与速度。

SPENCER: Self-Adaptive Model Distillation for Efficient Code Retrieval

  • 双编码器+交叉编码器混合结构,增强语义交互
  • 蒸馏后双编码器推理提速70%,性能保留超98%
  • 自适应选助教模型,适配不同预训练模型

代码检索旨在根据自然语言查询返回匹配的代码片段。随着深度学习发展,采用预训练模型已成为主流。现有方法多使用双编码器结构,分别编码查询和代码片段,但其底层缺乏两者交互,限制了性能。为兼顾效率与效果,本文提出SPENCER框架:先用双编码器缩小搜索空间,再用交叉编码器提升精度。为提高效率,提出新型模型蒸馏技术,使双编码器推理时间减少70%,同时保持超过98%的原始性能。此外,设计自适应教学助手选择策略,在蒸馏过程中动态选取适配的教师模型,确保不同预训练模型下的性能稳定。大量实验表明,双编码器与交叉编码器结合显著优于单一双编码器模型;所提蒸馏方法在大幅提速的同时几乎不损失性能。

原文摘要 · Abstract (English)

Code retrieval aims to provide users with desired code snippets based on users' natural language queries. With the development of deep learning technologies, adopting pre-trained models for this task has become mainstream. Considering the retrieval efficiency, most of the previous approaches adopt a dual-encoder for this task, which encodes the description and code snippet into representation vectors, respectively. However, the model structure of the dual-encoder tends to limit the model's performance, since it lacks the interaction between the code snippet and description at the bottom layer of the model during training. To improve the model's effectiveness while preserving its efficiency, we propose a framework, which adopts Self-AdaPtive Model Distillation for Efficient CodE Retrieval, named SPENCER. SPENCER first adopts the dual-encoder to narrow the search space and then adopts the cross-encoder to improve accuracy. To improve the efficiency of SPENCER, we propose a novel model distillation technique, which can greatly reduce the inference time of the dual-encoder while maintaining the overall performance. We also propose a teaching assistant selection strategy for our model distillation, which can adaptively select the suitable teaching assistant models for different pre-trained models during the model distillation to ensure the model performance. Extensive experiments demonstrate that the combination of dual-encoder and cross-encoder improves overall performance compared to solely dual-encoder-based models for code retrieval. Besides, our model distillation technique retains over 98% of the overall performance while reducing the inference time of the dual-encoder by 70%.

代码检索模型蒸馏双编码器

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