[论文解读] Simplifying Deep-Learning-Based Model for Code Search.
本文提出 CodeMatcher,一种基于深度学习的简化模型,用于代码搜索,结合了基于关键词的检索与方法名和方法体的模糊匹配,相较于 DeepCS 实现了 97% 的 MRR 提升和 66 倍的加速,同时在 41,000 个代码库的数据集上,相较于最先进的 IR 模型 CodeHow,MRR 提升了 73%。
To accelerate software development, developers frequently search and reuse existing code snippets from a large-scale codebase, e.g., GitHub. Over the years, researchers proposed many information retrieval (IR) based models for code search, which match keywords in query with code text. But they fail to connect the semantic gap between query and code. To conquer this challenge, Gu et al. proposed a deep-learning-based model named DeepCS. It jointly embeds method code and natural language description into a shared vector space, where methods related to a natural language query are retrieved according to their vector similarities. However, DeepCS' working process is complicated and time-consuming. To overcome this issue, we proposed a simplified model CodeMatcher that leverages the IR technique but maintains many features in DeepCS. Generally, CodeMatcher combines query keywords with the original order, performs a fuzzy search on name and body strings of methods, and returned the best-matched methods with the longer sequence of used keywords. We verified its effectiveness on a large-scale codebase with about 41k repositories. Experimental results showed the simplified model CodeMatcher outperforms DeepCS by 97% in terms of MRR (a widely used accuracy measure for code search), and it is over 66 times faster than DeepCS. Besides, comparing with the state-of-the-art IR-based model CodeHow, CodeMatcher also improves the MRR by 73%. We also observed that: fusing the advantages of IR-based and deep-learning-based models is promising because they compensate with each other by nature; improving the quality of method naming helps code search, since method name plays an important role in connecting query and code.
研究动机与目标
- 解决自然语言查询与代码片段之间的语义鸿沟问题。
- 在保持 DeepCS 语义匹配能力的同时,简化其复杂且缓慢的推理过程。
- 通过结合基于关键词的 IR 与受深度学习启发的向量对齐,提升检索的准确性和效率。
- 探究融合基于 IR 和深度学习的方法在代码搜索中的有效性。
- 评估方法命名质量对代码搜索性能的影响。
提出的方法
- CodeMatcher 使用原始顺序的查询关键词,构成查询序列,用于与方法名和方法体进行模糊匹配。
- 对方法名和方法体执行模糊字符串匹配,以识别相关的代码片段。
- 根据匹配中使用的关键词序列长度,返回最佳匹配的方法,优先选择更全面的匹配。
- 借鉴 DeepCS 的共享向量空间概念,但避免端到端训练,从而简化模型结构。
- 通过将查询关键词与代码元素对齐,保持语义相关性,同时依赖高效的字符串操作。
- 通过结合关键词匹配与语义对齐,整合基于 IR 和深度学习模型的优势。
实验结果
研究问题
- RQ1一个简化的模型能否在显著提升推理速度的同时,保持 DeepCS 的语义匹配能力?
- RQ2CodeMatcher 在 MRR 和速度方面与 DeepCS 及最先进的基于 IR 的模型(如 CodeHow)相比表现如何?
- RQ3方法名在多大程度上影响代码搜索的有效性?
- RQ4将基于 IR 的技术与深度学习原理相结合,能否提升代码搜索的准确性和效率?
- RQ5提升方法命名质量是否能带来更好的代码搜索结果?
主要发现
- 在包含 41,000 个代码库的大规模代码库上,CodeMatcher 的 MRR 相较于 DeepCS 提升了 97%。
- CodeMatcher 的速度比 DeepCS 快超过 66 倍,显著提升了推理效率。
- 与最先进的基于 IR 的模型 CodeHow 相比,CodeMatcher 的 MRR 提升了 73%。
- 融合基于 IR 和深度学习的方法具有潜力,因为二者能够互补彼此的优势。
- 提升方法命名质量可增强代码搜索性能,因为方法名在连接查询与代码方面起着关键作用。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。