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

APIGen:生成式API方法推荐

APIGen: Generative API Method Recommendation

Yujia Chen, Cuiyun Gao, Muyijie Zhu, Qing Liao, Yong Wang, Guoai Xu

AI总结:

针对现有API推荐方法依赖嵌入表示或大量标注数据的局限,提出含多样化示例选择与引导式推理的生成式方法APIGen,在公开基准上显著优于现有基线与大模型零样本效果。

摘要:

自动API方法推荐是代码智能领域的一项核心任务,旨在为编程查询推荐合适的API。现有方法主要可分为两大类:基于检索的方法和基于学习的方法。尽管这些方法已取得显著成效,但仍存在明显局限性:基于检索的方法依赖嵌入模型的文本表示能力,而基于学习的方法则需要大量任务特定的标注数据用于训练。为缓解这些局限,我们提出APIGen——一种通过增强上下文学习(ICL)实现的生成式API推荐方法。APIGen包含两个核心组件:(1)多样化示例选择。APIGen从词汇、句法和语义三个维度搜索与编程查询相似的帖子,为上下文学习提供信息量更丰富的示例。(2)引导式API推荐。APIGen让大语言模型(LLM)在生成API推荐前先执行推理,推理过程涉及查询背后的任务意图与API事实知识之间的细粒度匹配。借助该推理过程,APIGen使推荐的API更贴合查询的编程需求,同时提升了结果的可解释性。我们在两个公开基准上将APIGen与四种现有方法进行对比。实验表明,在SuccessRate@1指标上,APIGen在方法级API推荐任务中优于最优基线CLEAR 105.8%,在类级API推荐任务中优于后者54.3%。此外,在SuccessRate@3指标下的方法级API推荐任务中,APIGen相较于GPT-4等主流大语言模型的零样本性能,平均提升了49.87%。

英文摘要:

Automatic API method recommendation is an essential task of code intelligence, which aims to suggest suitable APIs for programming queries. Existing approaches can be categorized into two primary groups: retrieval-based and learning-based approaches. Although these approaches have achieved remarkable success, they still come with notable limitations. The retrieval-based approaches rely on the text representation capabilities of embedding models, while the learning-based approaches require extensive task-specific labeled data for training. To mitigate the limitations, we propose APIGen, a generative API recommendation approach through enhanced in-context learning (ICL). APIGen involves two main components: (1) Diverse Examples Selection. APIGen searches for similar posts to the programming queries from the lexical, syntactical, and semantic perspectives, providing more informative examples for ICL. (2) Guided API Recommendation. APIGen enables large language models (LLMs) to perform reasoning before generating API recommendations, where the reasoning involves fine-grained matching between the task intent behind the queries and the factual knowledge of the APIs. With the reasoning process, APIGen makes recommended APIs better meet the programming requirement of queries and also enhances the interpretability of results. We compare APIGen with four existing approaches on two publicly available benchmarks. Experiments show that APIGen outperforms the best baseline CLEAR by 105.8% in method-level API recommendation and 54.3% in class-level API recommendation in terms of SuccessRate@1. Besides, APIGen achieves an average 49.87% increase compared to the zero-shot performance of popular LLMs such as GPT-4 in method-level API recommendation regarding the SuccessRate@3 metric.

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

↑