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

将Python代码搜索视为基于双编码器的翻译检索问题

Approaching Code Search for Python as a Translation Retrieval Problem with Dual Encoders

Monoshiz Mahbub Khan, Zhe Yu

AI总结:

本研究将Python代码搜索转化为翻译检索问题,采用带余弦相似度损失的统一语言模型双编码器架构,在性能超越现有SOTA代码搜索模型的同时,大幅降低了时间与复杂度成本。

摘要:

代码搜索在软件系统的维护与扩展中至关重要。过往研究针对自然语言与编程语言工件,在配备多编码器及不同损失函数的模型上使用了独立的语言模型。与之类似,本研究将Python代码搜索视为一个翻译检索问题,将自然语言查询与编程语言视作两类语言。通过使用双编码器,这两类语言序列被映射到一个共享嵌入空间中,空间内的距离反映了给定查询与代码对之间的相似度。但与以往研究不同的是,该方法采用统一语言模型,以及带有余弦相似度损失函数的双编码器结构。统一语言模型有助于模型利用两类工件之间大量的词汇重叠,大幅降低学习难度。另一方面,采用余弦相似度损失训练的双编码器,能帮助模型学习底层模式,即哪些术语对预测关联的工件对至关重要。评估结果显示,所提出的模型性能优于当前最先进的代码搜索模型。此外,该模型在时间和复杂度方面的成本低得多,提供了一种更经济、更快速且性能更优的替代方案。

英文摘要:

Code search is vital in the maintenance and extension of software systems. Past works have used separate language models for the natural language and programming language artifacts on models with multiple encoders and different loss functions. Similarly, this work approaches code search for Python as a translation retrieval problem while the natural language queries and the programming language are treated as two types of languages. By using dual encoders, these two types of language sequences are projected onto a shared embedding space, in which the distance reflects the similarity between a given pair of query and code. However, in contrast to previous work, this approach uses a unified language model, and a dual encoder structure with a cosine similarity loss function. A unified language model helps the model take advantage of the considerable overlap of words between the artifacts, making the learning much easier. On the other hand, the dual encoders trained with cosine similarity loss helps the model learn the underlining patterns of which terms are important for predicting linked pairs of artifacts. Evaluation shows the proposed model achieves performance better than state-of-the-art code search models. In addition, this model is much less expensive in terms of time and complexity, offering a cheaper, faster, and better alternative.

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

↑