[论文解读] OCoR: An Overlapping-Aware Code Retriever
OCoR 是一种新型神经代码检索模型,通过使用字符级嵌入和可学习的重叠矩阵,显式建模自然语言描述与代码标识符之间的重叠,从而提升代码检索性能。该模型在 SQL 和 C# 数据集上实现了最先进性能,检索准确率相比现有方法提升了 13.1% 至 22.3%。
Code retrieval helps developers reuse the code snippet in the open-source projects. Given a natural language description, code retrieval aims to search for the most relevant code among a set of code. Existing state-of-the-art approaches apply neural networks to code retrieval. However, these approaches still fail to capture an important feature: overlaps. The overlaps between different names used by different people indicate that two different names may be potentially related (e.g., "message" and "msg"), and the overlaps between identifiers in code and words in natural language descriptions indicate that the code snippet and the description may potentially be related. To address these problems, we propose a novel neural architecture named OCoR, where we introduce two specifically-designed components to capture overlaps: the first embeds identifiers by character to capture the overlaps between identifiers, and the second introduces a novel overlap matrix to represent the degrees of overlaps between each natural language word and each identifier. The evaluation was conducted on two established datasets. The experimental results show that OCoR significantly outperforms the existing state-of-the-art approaches and achieves 13.1% to 22.3% improvements. Moreover, we also conducted several in-depth experiments to help understand the performance of different components in OCoR.
研究动机与目标
- 解决现有神经代码检索模型在捕捉自然语言描述与代码标识符之间语义重叠方面的局限性。
- 建模名称之间的重叠子串(例如 'Sort' 和 'QuickSort')以及代码标识符与自然语言词汇之间的重叠(例如 'joint_table_b' 和 'joint table')。
- 设计一种神经架构,显式编码重叠特征以提升检索的相关性。
- 通过在基准数据集上的消融实验和对比实验,验证重叠感知组件的有效性。
提出的方法
- 使用字符级嵌入表示单词和标识符,使模型能够捕捉用于表示相似概念的不同名称之间的子串重叠。
- 引入一种新颖的重叠矩阵,利用最长公共子串(LCS)作为度量,量化自然语言描述中的每个词与代码片段中每个标识符之间的重叠程度。
- 将重叠矩阵与基于 Transformer 的编码器生成的上下文嵌入相结合,以增强表征学习。
- 通过在多个检索模型上应用集成学习,进一步提升性能。
- 使用对比损失端到端训练模型,以优化将相关代码片段排在更高位置的排序目标。
实验结果
研究问题
- RQ1显式建模自然语言描述与代码标识符之间的子串重叠,是否能够提升代码检索性能?
- RQ2字符级嵌入在通过重叠子串捕捉开发者命名标识符之间的语义相似性方面有多有效?
- RQ3基于 LCS 的重叠矩阵与标准嵌入方法相比,能在多大程度上提升检索准确率?
- RQ4OCoR 架构中的哪些组件对性能提升贡献最为显著?
- RQ5该方法能否泛化到 SQL 和 C# 之外的其他编程语言?
主要发现
- 在两个成熟的代码检索数据集上,OCoR 相较于最先进基线模型,检索性能提升了 13.1% 至 22.3%。
- 消融研究证实,字符级嵌入和重叠矩阵两个组件对性能提升均至关重要。
- 重叠矩阵显著增强了模型关联语义相关但拼写不同的术语(例如 'msg' 和 'message')的能力。
- 多个模型的集成进一步提升了性能,表明结合多样化的检索信号具有显著优势。
- 该模型在重叠频率较高的代码上表现出良好的泛化能力,StaQC 数据集中 89.12% 的实例至少包含一个重叠子串。
- 该方法在扩展至 Python、Java 和 C++ 等其他编程语言方面展现出强大潜力。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。