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

Author:

Ma Wei1ORCID,Liu Shangqing2ORCID,Zhao Mengjie3ORCID,Xie Xiaofei4ORCID,Wang Wenhang5ORCID,Hu Qiang6ORCID,Zhang Jie7ORCID,Liu Yang2ORCID

Affiliation:

1. College of Computing and Data Science (CCDS), Nanyang Technological University, Singapore, Singapore

2. Nanyang Technological University, Singapore, Singapore

3. Ludwig Maximilian University of Munich, Munich, Germany

4. Singapore Management University, Singapore, Singapore

5. University of Alberta, Edmonton, Canada

6. The University of Tokyo, Tokyo, Japan

7. Noah's Ark Lab, Huawei, Xi'an, China

Abstract

Code models have made significant advancements in code intelligence by encoding knowledge about programming languages. While previous studies have explored the capabilities of these models in learning code syntax, there has been limited investigation on their ability to understand code semantics. Additionally, existing analyses assume that the number of edges between nodes at the abstract syntax tree (AST) is related to syntax distance, and also often require transforming the high-dimensional space of deep learning models to a low-dimensional one, which may introduce inaccuracies. To study how code models represent code syntax and semantics, we conduct a comprehensive analysis of seven code models, including four representative code pre-trained models (CodeBERT, GraphCodeBERT, CodeT5, and UnixCoder) and three large language models (LLMs) (StarCoder, CodeLlama and CodeT5+). We design four probing tasks to assess the models’ capacities in learning both code syntax and semantics. These probing tasks reconstruct code syntax and semantics structures (AST, control dependence graph (CDG), data dependence graph (DDG), and control flow graph (CFG)) in the representation space. These structures are core concepts for code understanding. We also investigate the syntax token role in each token representation and the long dependency between the code tokens. Additionally, we analyze the distribution of attention weights related to code semantic structures. Through extensive analysis, our findings highlight the strengths and limitations of different code models in learning code syntax and semantics. The results demonstrate that these models excel in learning code syntax, successfully capturing the syntax relationships between tokens and the syntax roles of individual tokens. However, their performance in encoding code semantics varies. CodeT5 and CodeBERT demonstrate proficiency in capturing control and data dependencies, whereas UnixCoder shows weaker performance in this aspect. We do not observe LLMs generally performing much better than pre-trained models. The shallow layers of LLMs perform better than their deep layers. The investigation of attention weights reveals that different attention heads play distinct roles in encoding code semantics. Our research findings emphasize the need for further enhancements in code models to better learn code semantics. This study contributes to the understanding of code models’ abilities in syntax and semantics analysis. Our findings provide guidance for future improvements in code models, facilitating their effective application in various code-related tasks.

Funder

National Research Foundation, Singapore

National Cybersecurity R&D Programme

DSO National Laboratories

NRF Investigatorship

National Research Foundation, Singapore and Cyber Security Agency of Singapore

Publisher

Association for Computing Machinery (ACM)

Reference81 articles.

1. Unified pre-training for program understanding and generation;Ahmad Wasi Uddin;arXiv preprint arXiv:2103.06333,2021

2. A Survey of Machine Learning for Big Code and Naturalness

3. Exploring software naturalness through neural language models;Buratti Luca;arXiv preprint arXiv:2006.12641,2020

4. The advantages of the Matthews correlation coefficient (MCC) over F1 score and accuracy in binary classification evaluation

同舟云学术

1.学者识别学者识别

2.学术分析学术分析

3.人才评估人才评估

"同舟云学术"是以全球学者为主线,采集、加工和组织学术论文而形成的新型学术文献查询和分析系统,可以对全球学者进行文献检索和人才价值评估。用户可以通过关注某些学科领域的顶尖人物而持续追踪该领域的学科进展和研究前沿。经过近期的数据扩容,当前同舟云学术共收录了国内外主流学术期刊6万余种,收集的期刊论文及会议论文总量共计约1.5亿篇,并以每天添加12000余篇中外论文的速度递增。我们也可以为用户提供个性化、定制化的学者数据。欢迎来电咨询!咨询电话:010-8811{复制后删除}0370

www.globalauthorid.com

TOP

Copyright © 2019-2024 北京同舟云网络信息技术有限公司
京公网安备11010802033243号  京ICP备18003416号-3