The study of code example recommendation has been conducted extensively in the past and recently in order to assist developers in their software development tasks. This is because developers often spend significant time searching for relevant code examples on the internet, utilizing open-source projects and informal documentation. For finding useful code examples, informal documentation, such as Stack Overflow discussions and forums, can be invaluable. We have focused our research on Stack Overflow, which is a popular resource for discussing different topics among software developers. For increasing the quality of the recommended code examples, we have collected and recommended the best code examples in the Java programming language. We have utilized BERT in our approach, which is a Large Language Model (LLM) for text representation that can effectively extract semantic information from textual data. Our first step involved using BERT to convert code examples into numerical vectors. Subsequently, we applied LSH to identify Approximate Nearest Neighbors (ANN). Our research involved the implementation of two variants of this approach, namely the Random Hyperplane-based LSH and the Query-Aware LSH. Our study compared two algorithms using four parameters: HitRate, Mean Reciprocal Rank (MRR), Average Execution Time, and Relevance. The results of our analysis revealed that the Query- Aware (QA) approach outperformed the Random Hyperplane-based (RH) approach in terms of HitRate. Specifically, the QA approach achieved a HitRate improvement of 20% to 35% for query pairs compared to the RH approach. Creating hashing tables and assigning data samples to buckets using the QA approach is at least four times faster than the RH approach. The QA approach returns code examples within milliseconds, while it takes several seconds (sec) for the RH approach to recommend code examples.
翻译:代码示例推荐的研究在过去及近期已被广泛开展,旨在帮助开发人员完成软件开发任务。这是因为开发人员常常花费大量时间在互联网上搜索相关代码示例,利用开源项目和非正式文档。对于寻找有用的代码示例,非正式文档(如Stack Overflow讨论和论坛)可能具有不可估量的价值。我们的研究聚焦于Stack Overflow,这是一个软件开发人员讨论不同主题的热门资源。为提高推荐代码示例的质量,我们收集并推荐了Java编程语言中最优的代码示例。我们在方法中采用了BERT,这是一种用于文本表示的大型语言模型(LLM),能够有效提取文本数据中的语义信息。我们的第一步是利用BERT将代码示例转换为数值向量。随后,我们应用局部敏感哈希(LSH)来识别近似最近邻(ANN)。我们的研究实现了该方法的两种变体,即基于随机超平面的LSH和查询感知型LSH。我们通过四个参数比较了两种算法:命中率、平均倒数排名(MRR)、平均执行时间和相关性。分析结果表明,查询感知型(QA)方法在命中率方面优于基于随机超平面(RH)的方法。具体而言,与RH方法相比,QA方法在查询对上的命中率提升了20%至35%。使用QA方法创建哈希表并将数据样本分配到桶中的速度至少比RH方法快四倍。QA方法能在毫秒内返回代码示例,而RH方法推荐代码示例则需要数秒时间。