arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2407.04868cs.AIcs.SE
收藏

探究黑盒代码语言模型的内部机制

Looking into Black Box Code Language Models

University of Kentucky(肯塔基大学);Louisiana State University(路易斯安那州立大学)

Muhammad Umair Haider, Umar Farooq, A. B. Siddique, Mark Marron

AI总结:

本文通过分析Codegen-Mono和Ploycoder的前馈层,揭示代码语言模型中低层捕获语法、高层编码语义,并验证概念可编辑性及不同层在上下文预测中的分工。

摘要:

语言模型(LMs)已经展示了其在代码相关任务中的应用,并且最近提出了多种代码语言模型(code LMs)。这一方向的大多数研究仅关注语言模型在不同基准上的性能提升,而语言模型被视为黑盒。除此之外,少数工作试图理解注意力层在代码语言模型中的作用。然而,前馈层仍然未被充分探索,而前馈层占典型Transformer模型参数的三分之二。在这项工作中,我们试图通过检查前馈层来深入了解代码语言模型的内部工作机制。为了开展研究,我们使用了两个最先进的代码语言模型Codegen-Mono和Ploycoder,以及三种广泛使用的编程语言Java、Go和Python。我们重点考察存储概念的组织方式、这些概念的可编辑性,以及不同层和输入上下文大小变化对输出生成的作用。我们的实证结果表明,较低层捕获语法模式,而较高层编码抽象概念和语义。我们展示了感兴趣的概念可以在前馈层内被编辑,而不会损害代码语言模型的性能。此外,我们观察到初始层充当“思考”层,而后续层对于预测后续代码token至关重要。进一步地,我们发现较早的层可以准确预测较小的上下文,但较大的上下文需要关键后续层的贡献。我们预期这些发现将有助于更好地理解、调试和测试代码语言模型。

英文摘要:

Language Models (LMs) have shown their application for tasks pertinent to code and several code~LMs have been proposed recently. The majority of the studies in this direction only focus on the improvements in performance of the LMs on different benchmarks, whereas LMs are considered black boxes. Besides this, a handful of works attempt to understand the role of attention layers in the code~LMs. Nonetheless, feed-forward layers remain under-explored which consist of two-thirds of a typical transformer model's parameters. In this work, we attempt to gain insights into the inner workings of code language models by examining the feed-forward layers. To conduct our investigations, we use two state-of-the-art code~LMs, Codegen-Mono and Ploycoder, and three widely used programming languages, Java, Go, and Python. We focus on examining the organization of stored concepts, the editability of these concepts, and the roles of different layers and input context size variations for output generation. Our empirical findings demonstrate that lower layers capture syntactic patterns while higher layers encode abstract concepts and semantics. We show concepts of interest can be edited within feed-forward layers without compromising code~LM performance. Additionally, we observe initial layers serve as ``thinking'' layers, while later layers are crucial for predicting subsequent code tokens. Furthermore, we discover earlier layers can accurately predict smaller contexts, but larger contexts need critical later layers' contributions. We anticipate these findings will facilitate better understanding, debugging, and testing of code~LMs.

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

↑