arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2212.10017cs.SEcs.AI
收藏

揭秘代码预训练模型:语法与语义能力探究

Unveiling Code Pre-Trained Models: Investigating Syntax and Semantics Capacities

Nanyang Technological University(南洋理工大学);Ludwig Maximilian University of Munich(慕尼黑大学);Singapore Management University(新加坡管理大学);University of Alberta(阿尔伯塔大学);The University of Tokyo(东京大学);Noah’s Ark Lab, Huawei(华为诺亚方舟实验室)

Wei Ma, Shangqing Liu, Mengjie Zhao, Xiaofei Xie, Wenhan Wang, Qiang Hu, Jie Zhang, Yang Liu

AI总结:

该研究针对代码预训练模型语义理解不足的问题,通过四项探测任务分析七款代码模型的语法语义表征能力,明确了各类模型的优缺点,为后续代码模型优化提供了参考。

摘要:

过往研究已考察了这类模型对代码语法的掌握程度,但它们对代码语义的理解仍有待探索。我们对七款代码模型展开了全面分析,以探究代码模型如何表征代码语法与语义,其中包括四款主流代码预训练模型(CodeBERT、GraphCodeBERT、CodeT5和UnixCoder)以及三款大语言模型(StarCoder、CodeLlama和CodeT5+)。我们设计了四项探测任务来评估模型学习代码语法与语义的能力,这些任务聚焦于在模型的表征空间中重构代码语法与语义结构——例如AST(抽象语法树)、CFG(控制流图)、CDG(控制依赖图)和DDG(数据依赖图),这些结构是理解代码的基础。此外,我们还探究了语法标记在各标记表征中的作用,以及代码标记之间的扩展依赖关系,同时考察了注意力权重在代码语义结构上的分布情况。通过细致分析,我们的结果凸显了各类代码模型在掌握代码语法与语义方面的优缺点。研究发现表明,这些模型擅长掌握代码语法,能够有效捕捉语法标记的关系与作用,但它们编码代码语义的能力表现出更大的差异性。本研究丰富了我们对代码模型语法语义分析能力的认知,研究结果为未来代码模型的优化升级提供了宝贵洞见,有助于优化其在各类代码相关任务中的应用。

英文摘要:

Past research has examined how well these models grasp code syntax, yet their understanding of code semantics still needs to be explored. We extensively analyze seven code models to investigate how code models represent code syntax and semantics. This includes four prominent code pre-trained models (CodeBERT, GraphCodeBERT, CodeT5, and UnixCoder) and three large language models (StarCoder, CodeLlama, and CodeT5+). We have developed four probing tasks to evaluate the models' abilities to learn code syntax and semantics. These tasks focus on reconstructing code syntax and semantic structures-such as AST, CFG, CDG, and DDG - within the models' representation spaces. These structures are fundamental to understanding code. Additionally, we explore the role of syntax tokens in each token representation and the extended dependencies among code tokens. Furthermore, we examine the distribution of attention weights concerning code semantic structures. Through detailed analysis, our results emphasize the strengths and weaknesses of various code models in mastering code syntax and semantics. The findings reveal that these models are proficient in grasping code syntax, effectively capturing the relationships and roles of syntax tokens. However, their ability to encode code semantics shows more variability. This study enriches our understanding of the capabilities of code models in analyzing syntax and semantics. Our findings offer valuable insights for future code model enhancements, helping optimize their application across a range of code-related tasks.

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

↑