Pop Quiz! Do Pre-trained Code Models Possess Knowledge of Correct API Names?
Monash University(莫纳什大学);CSIRO’s Data61(联邦科学与工业研究组织Data61);Australian National University(澳大利亚国立大学);Beihang University(北京航空航天大学);University of New South Wales(新南威尔士大学)
Terry Yue Zhuo, Xiaoning Du, Zhenchang Xing, Jiamou Sun, Haowei Quan, Li Li, Liming Zhu
预训练代码模型(如 CodeBERT 和 Codex)的最新突破已展现出其在各种下游任务中的卓越性能。在这些代码模型中,API 使用的正确性和无歧义性对于实现理想的程序功能至关重要,这要求它们在结构和语义上学习各种 API 全限定名。近期研究揭示,即使是最先进的预训练代码模型在代码生成期间也难以建议正确的 API。然而,对于这种糟糕的 API 使用性能的原因却鲜少被研究。为了应对这一挑战,我们提出使用知识探测作为解释代码模型的一种手段,该方法使用完形填空式测试来衡量存储在模型中的知识。我们的综合研究从 API 调用和 API 导入两个不同视角考察了代码模型理解 API 全限定名的能力。具体而言,我们揭示了当前代码模型在理解 API 名称方面存在困难,且预训练策略显著影响 API 名称学习的质量。我们证明,自然语言上下文可以辅助代码模型定位 Python API 名称,并将 Python API 名称知识泛化到未见数据。我们的发现提供了对当前预训练代码模型局限性和能力的见解,并建议将 API 结构纳入预训练过程可以改善自动 API 使用和代码表示。这项工作对推进代码智能实践具有重要意义,并为未来研究指明了方向。本工作中使用的所有实验结果、数据和源代码可在 https://doi.org/10.5281/zenodo.7902072 获取。
英文摘要:
Recent breakthroughs in pre-trained code models, such as CodeBERT and Codex, have shown their superior performance in various downstream tasks. The correctness and unambiguity of API usage among these code models are crucial for achieving desirable program functionalities, requiring them to learn various API fully qualified names structurally and semantically. Recent studies reveal that even state-of-the-art pre-trained code models struggle with suggesting the correct APIs during code generation. However, the reasons for such poor API usage performance are barely investigated. To address this challenge, we propose using knowledge probing as a means of interpreting code models, which uses cloze-style tests to measure the knowledge stored in models. Our comprehensive study examines a code model's capability of understanding API fully qualified names from two different perspectives: API call and API import. Specifically, we reveal that current code models struggle with understanding API names, with pre-training strategies significantly affecting the quality of API name learning. We demonstrate that natural language context can assist code models in locating Python API names and generalize Python API name knowledge to unseen data. Our findings provide insights into the limitations and capabilities of current pre-trained code models, and suggest that incorporating API structure into the pre-training process can improve automated API usage and code representations. This work provides significance for advancing code intelligence practices and direction for future studies. All experiment results, data and source code used in this work are available at \url{https://doi.org/10.5281/zenodo.7902072}.
Don't Use a Cannon to Kill a Fly: Lightweight Model Editing for LLMs to Correct Deprecated API Recommendations
Department of Computer Science, City University of Hong Kong(香港城市大学计算机系);The State Key Laboratory of Blockchain and Data Security, Zhejiang University(浙江大学区块链与数据安全国家重点实验室);Hangzhou High-Tech Zone (Binjiang) Institute of Blockchain and Data Security(杭州高新技术开发区(滨江)区块链与数据安全研究院);Midea Group(美的集团)