基于BERT和查询感知LSH改进非官方文档中的代码示例推荐:一项对比研究
Improving Code Example Recommendations on Informal Documentation Using BERT and Query-Aware LSH: A Comparative Study
AI总结:
本研究针对Stack Overflow平台的Java代码示例推荐场景,结合BERT与两种LSH方法进行对比,发现查询感知LSH在命中率和效率上更优,且与现有前沿基准方法效率相当。
摘要:
我们的研究聚焦于为软件开发人员推荐代码示例,这种做法通过提供现成可用的代码片段能为开发者节省大量时间。本研究的关注对象是Stack Overflow——一个常用于编程讨论和解决方案查询的资源平台,研究具体围绕Java编程语言的场景展开。我们应用了BERT这一强大的大语言模型(Large Language Model, LLM),它能够通过提取代码示例的语义信息将其转换为数值向量。在得到这些数值表示后,我们使用局部敏感哈希(Locality-Sensitive Hashing, LSH)来识别近似最近邻(Approximate Nearest Neighbors, ANN)。本研究采用了两种LSH变体:基于随机超平面的LSH和查询感知(Query-Aware)LSH。我们从四个参数维度对这两种方法进行了严格对比,分别是命中率(HitRate)、平均倒数排名(Mean Reciprocal Rank, MRR)、平均执行时间和相关性。研究结果显示,查询感知(QA)方法的表现优于基于随机超平面(RH)的方法。具体而言,在查询对的命中率上,QA方法相比RH方法有20%到35%的显著提升。此外,QA方法的时间效率明显更高,其创建哈希表以及将数据样本分配到桶中的速度至少快四倍。QA方法能在数毫秒内返回代码示例,而RH方法推荐代码示例通常需要数秒时间。鉴于QA方法的优异性能,我们将其与当前最先进的基准方法PostFinder和FaCoY进行了对比测试。我们的QA方法展现出了相当的效率,证明了其在高效代码推荐方面的潜力。
英文摘要:
Our research investigates the recommendation of code examples to aid software developers, a practice that saves developers significant time by providing ready-to-use code snippets. The focus of our study is Stack Overflow, a commonly used resource for coding discussions and solutions, particularly in the context of the Java programming language. We applied BERT, a powerful Large Language Model (LLM) that enables us to transform code examples into numerical vectors by extracting their semantic information. Once these numerical representations are prepared, we identify Approximate Nearest Neighbors (ANN) using Locality-Sensitive Hashing (LSH). Our research employed two variants of LSH: Random Hyperplane-based LSH and Query-Aware LSH. We rigorously compared these two approaches across four parameters: HitRate, Mean Reciprocal Rank (MRR), Average Execution Time, and Relevance. Our study revealed that the Query-Aware (QA) approach showed superior performance over the Random Hyperplane-based (RH) method. Specifically, it exhibited a notable improvement of 20\% to 35\% in HitRate for query pairs compared to the RH approach. Furthermore, the QA approach proved significantly more time-efficient, with its speed in creating hashing tables and assigning data samples to buckets being at least four times faster. It can return code examples within milliseconds, whereas the RH approach typically requires several seconds to recommend code examples. Due to the superior performance of the QA approach, we tested it against PostFinder and FaCoY, the state-of-the-art baselines. Our QA method showed comparable efficiency proving its potential for effective code recommendation.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。