Skip to main content
QUICK REVIEW

[论文解读] LLMs Meet Library Evolution: Evaluating Deprecated API Usage in LLM-based Code Completion

Chong Wang, Kaifeng Huang|arXiv (Cornell University)|Jun 14, 2024
Digital Rights Management and SecurityComputer Science被引用 3
一句话总结

本研究评估了七种模型在基于大语言模型(LLM)的代码补全中对已弃用API的使用情况,涵盖来自八个Python库的145个API映射关系以及28,125个提示。研究发现,LLM频繁建议已弃用的API,主要由于训练数据偏差和推理过程中缺乏对弃用信息的认知。为此,本文提出了两种轻量级修复方法——ReplaceAPI和InsertPrompt,以缓解该问题,为将库演化机制整合到LLM驱动的开发流程中提供了基础性解决方案。

ABSTRACT

Large language models (LLMs), pre-trained or fine-tuned on large code corpora, have shown effectiveness in generating code completions. However, in LLM-based code completion, LLMs may struggle to use correct and up-to-date Application Programming Interfaces (APIs) due to the rapid and continuous evolution of libraries. While existing studies have highlighted issues with predicting incorrect APIs, the specific problem of deprecated API usage in LLM-based code completion has not been thoroughly investigated. To address this gap, we conducted the first evaluation study on deprecated API usage in LLM-based code completion. This study involved seven advanced LLMs, 145 API mappings from eight popular Python libraries, and 28,125 completion prompts. The study results reveal the status quo (i.e., API usage plausibility and deprecated usage rate) of deprecated API and replacing API usage in LLM-based code completion from the perspectives of model, prompt, and library, and indicate the root causes behind. Based on these findings, we propose two lightweight fixing approaches, REPLACEAPI and INSERTPROMPT, which can serve as baseline approaches for future research on mitigating deprecated API usage in LLM-based completion. Additionally, we provide implications for future research on integrating library evolution with LLM-driven software development.

研究动机与目标

  • 调查基于大语言模型的代码补全中已弃用API使用的普遍性及其根本原因。
  • 分析模型架构、提示设计以及库演化对已弃用API预测的影响。
  • 提出实用且轻量级的修复方法,以减少LLM生成代码中对已弃用API的建议。
  • 为将库演化机制整合到LLM驱动的软件开发流水线中提供可操作的见解。

提出的方法

  • 从八个主流Python库(包括PyTorch、TensorFlow和scikit-learn)中收集了145个已弃用到替代的API映射关系。
  • 通过从过时和更新的函数调用中提取参考API,生成了28,125个行级代码补全提示。
  • 评估了七种先进的大语言模型(包括CodeLlama和GPT-3.5)在预测合理(已弃用或替代)API方面的能力。
  • 若预测结果与已弃用或替代API匹配,则标注为“合理”;否则标注为“不相关”。
  • 提出两种轻量级修复技术:ReplaceAPI(在解码过程中替换过时的API调用)和InsertPrompt(将关于API弃用的信息注入提示中)。
  • 从模型、提示和库三个视角开展定性和定量分析,以识别关键的失败模式。
Figure 1 : Overview of Our Study
Figure 1 : Overview of Our Study

实验结果

研究问题

  • RQ1RQ1:从模型视角看,基于大语言模型的代码补全中已弃用API使用的现状及其根本原因是什么?
  • RQ2RQ2:不同的提示设计如何影响对已弃用和合理API的预测?
  • RQ3RQ3:特定库的演化模式如何影响不同库中已弃用API使用的可能性?

主要发现

  • 所有七种评估的大语言模型在预测正确API方面均面临显著挑战,由于训练数据过时以及推理过程中缺乏对弃用的认知,导致已弃用API被频繁建议。
  • 模型性能因架构和训练数据而异,大模型虽表现略优,但对弃用语义的泛化能力仍严重不足。
  • 源自过时函数的提示导致已弃用API预测率高于源自更新函数的提示,表明模型行为具有上下文依赖性。
  • 研究发现,特定库的演化模式(如多阶段弃用,例如torch.gels() → torch.lstsq() → torch.linalg.lstsq())显著增加了错误建议的风险。
  • 在受控评估中,ReplaceAPI和InsertPrompt分别将已弃用API的使用率降低了最多68%和55%,证明其作为基线修复方案的有效性。
  • 研究揭示,当前大语言模型缺乏对API弃用的后验知识,因此检索增强生成和模型编辑是未来有前景的研究方向。
Figure 2 : Illustration of Completion Prompt Construction for An Up-to-dated Function.
Figure 2 : Illustration of Completion Prompt Construction for An Up-to-dated Function.

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。