arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2404.01903cs.CLcs.LGcs.PL
收藏

通过激活引导理解CodeLLM如何(错误)预测类型

Understanding How CodeLLMs (Mis)Predict Types with Activation Steering

Khoury College of Computer Sciences(科里学院计算机科学系);Northeastern University(东北大学)

Francesca Lucchetti, Arjun Guha

AI总结:

本研究针对CodeLLM在语义无关语法改动下类型预测性能下降的问题,构建对抗样本数据集验证其鲁棒性不足,通过激活引导激活跨语言的鲁棒类型预测机制,证明LLM能习得可跨语言迁移的代码语义表示。

摘要:

大语言模型(LLM)被软件工程师广泛用于编程任务。然而研究表明,LLM往往缺乏对程序语义的深度理解,即使是语法上的微小改动(如重命名变量),也会导致其在各类任务上的性能显著下降。本研究聚焦类型预测任务:给定一个部分标注类型的程序,模型能否预测缺失的类型注解,从而让程序的类型标注更完整?我们构建了一个对抗样本数据集——模型最初能在这些样本上预测出正确类型,但经过语义无关的编辑后就会开始出错。这一问题值得关注,因为理想情况下模型应能在语义等价代码的不同语法形式间泛化。这种鲁棒性的缺失表明,模型对代码语义的理解可能较为浅层。尽管如此,我们提供的证据表明,LLM实际上确实习得了鲁棒的类型预测机制,只是这些机制在对抗场景下往往无法被激活。通过使用激活引导(一种操纵模型内部激活、引导其调用潜在知识的方法),我们恢复了模型在对抗输入上的准确预测。我们证明,引导操作成功激活了一种Python和TypeScript共有的类型预测机制,且效果优于使用上下文示例的提示方法。对五种不同模型的综合评估表明,LLM能够习得可泛化的代码语义表示,且这类表示可跨编程语言迁移。

英文摘要:

Large Language Models (LLMs) are widely used by software engineers for programming tasks. However, research shows that LLMs often lack a deep understanding of program semantics. Even minor changes to syntax, such as renaming variables, can significantly degrade performance across various tasks. In this work, we examine the task of type prediction: given a partially typed program, can a model predict a missing type annotations such that the resulting program is more typed? We construct a dataset of adversarial examples where models initially predict the correct types, but begin to fail after semantically irrelevant edits. This is problematic, as models should ideally generalize across different syntactic forms of semantically equivalent code. This lack of robustness suggests that models may have a shallow understanding of code semantics. Despite this, we provide evidence that LLMs do, in fact, learn robust mechanisms for type prediction-though these mechanisms often fail to activate in adversarial scenarios. By using activation steering, a method that manipulates a model's internal activations to guide it toward using latent knowledge, we restore accurate predictions on adversarial inputs. We show that steering successfully activates a type prediction mechanism that is shared by both Python and TypeScript, and is more effective than prompting with in-context examples. Across five different models, our comprehensive evaluation demonstrates that LLMs can learn generalizable representations of code semantics that transfer across programming languages.

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

↑