paperbot · PL 论文追踪

全部论文 待读 收藏

P2 What do they capture?

它们捕捉到了什么?——对预训练代码语言模型的结构分析
ICSE Proceedings of the 44th International Conference on Software Engineering2022匹配度 2/10 · 论文分析预训练代码模型对代码语法结构的捕捉,属于代码模型可解释性研究,与用户关注的静态分析/形式化验证、浮点程序分析、贝叶斯程序分析以及 Agentic 程序分析无直接交集;仅与‘代码模型是否理解程序结构’有微弱关联。引用 139 inbox
Yao Wan, Wei Zhao, Hongyu Zhang, Yulei Sui, Guandong Xu, Hai Jin
crossref: 2026-09-12dblp: 2026-09-12arxiv: 2026-09-12

AI 速览

一句话:从注意力、词嵌入探针与句法树归纳三方面分析,揭示预训练代码模型能捕捉代码句法结构。

该文针对预训练代码语言模型(如 CodeBERT、GraphCodeBERT)可解释性不足的问题,追问这些基于掩码预训练与 Transformer 的模型为何有效、能捕捉何种特征关联。作者从三个视角进行结构分析:(1)注意力分析,考察注意力权重与代码句法结构的关系;(2)词嵌入探针,检验中间表示是否保留句法信息;(3)句法树归纳,评估模型恢复代码句法树的能力。分析发现:注意力与代码句法结构高度对齐;预训练代码语言模型能在各 Transformer 层的中间表示中保留代码句法结构;模型具备归纳代码句法树的能力。这些发现表明,在预训练过程中融入代码句法结构可能有助于获得更好的代码表示,为后续研究提供了启示。

问题
预训练代码语言模型(如 CodeBERT、GraphCodeBERT)在下游代码智能任务上表现良好,但其可解释性不足,尚不清楚模型为何有效以及能捕捉哪些特征关联。
方法
从注意力分析、词嵌入探针与句法树归纳三个不同视角,对预训练代码语言模型进行结构性分析,以解释其内部行为与所捕捉的代码特征。
评估
在 CodeBERT、GraphCodeBERT 等预训练代码模型上开展综合分析,通过注意力对齐、探针与句法树归纳实验揭示其捕捉代码句法结构的能力。
原文摘要(Abstract)

Recently, many pre-trained language models for source code have been proposed to model the context of code and serve as a basis for downstream code intelligence tasks such as code completion, code search, and code summarization. These models leverage masked pre-training and Transformer and have achieved promising results. However, currently there is still little progress regarding interpretability of existing pre-trained code models. It is not clear why these models work and what feature correlations they can capture. In this paper, we conduct a thorough structural analysis aiming to provide an interpretation of pre-trained language models for source code (e.g., CodeBERT, and GraphCodeBERT) from three distinctive perspectives: (1) attention analysis, (2) probing on the word embedding, and (3) syntax tree induction. Through comprehensive analysis, this paper reveals several insightful findings that may inspire future studies: (1) Attention aligns strongly with the syntax structure of code. (2) Pre-training language models of code can preserve the syntax structure of code in the intermediate representations of each Transformer layer. (3) The pre-trained models of code have the ability of inducing syntax trees of code. Theses findings suggest that it may be helpful to incorporate the syntax structure of code into the process of pre-training for better code representations.

链接与引用

DOI 原文 · arXiv · DBLP

BibTeX
@inproceedings{abs-2202-06840,
  title = {What do they capture?},
  author = {Yao Wan and Wei Zhao and Hongyu Zhang and Yulei Sui and Guandong Xu and Hai Jin},
  booktitle = {ICSE},
  year = {2022},
  doi = {10.1145/3510003.3510050}
}