Mechanistic Understanding of Language Models in Syntactic Code Completion

Fuente: arXiv
Enregistré dans:
Détails bibliographiques
Auteurs principaux: Miller, Samuel, Rai, Daking, Yao, Ziyu
Format: Preprint
Publié: 2025
Sujets:
Accès en ligne:
Tags: Ajouter un tag
Pas de tags, Soyez le premier à ajouter un tag!
_version_ 1866929732233199616
author Miller, Samuel
Rai, Daking
Yao, Ziyu
author_facet Miller, Samuel
Rai, Daking
Yao, Ziyu
contents Recently, language models (LMs) have shown impressive proficiency in code generation tasks, especially when fine-tuned on code-specific datasets, commonly known as Code LMs. However, our understanding of the internal decision-making processes of Code LMs, such as how they use their (syntactic or semantic) knowledge, remains limited, which could lead to unintended harm as they are increasingly used in real life. This motivates us to conduct one of the first Mechanistic Interpretability works to understand how Code LMs perform a syntactic completion task, specifically the closing parenthesis task, on the CodeLlama-7b model (Roziere et al. 2023). Our findings reveal that the model requires middle-later layers until it can confidently predict the correct label for the closing parenthesis task. Additionally, we identify that while both multi-head attention (MHA) and feed-forward (FF) sub-layers play essential roles, MHA is particularly crucial. Furthermore, we also discover attention heads that keep track of the number of already closed parentheses precisely but may or may not promote a correct number of closing parentheses that are still missing, leading to a positive or negative impact on the model's performance.
format Preprint
id arxiv_https___arxiv_org_abs_2502_18499
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Mechanistic Understanding of Language Models in Syntactic Code Completion
Miller, Samuel
Rai, Daking
Yao, Ziyu
Software Engineering
Artificial Intelligence
Computation and Language
I.2.7
Recently, language models (LMs) have shown impressive proficiency in code generation tasks, especially when fine-tuned on code-specific datasets, commonly known as Code LMs. However, our understanding of the internal decision-making processes of Code LMs, such as how they use their (syntactic or semantic) knowledge, remains limited, which could lead to unintended harm as they are increasingly used in real life. This motivates us to conduct one of the first Mechanistic Interpretability works to understand how Code LMs perform a syntactic completion task, specifically the closing parenthesis task, on the CodeLlama-7b model (Roziere et al. 2023). Our findings reveal that the model requires middle-later layers until it can confidently predict the correct label for the closing parenthesis task. Additionally, we identify that while both multi-head attention (MHA) and feed-forward (FF) sub-layers play essential roles, MHA is particularly crucial. Furthermore, we also discover attention heads that keep track of the number of already closed parentheses precisely but may or may not promote a correct number of closing parentheses that are still missing, leading to a positive or negative impact on the model's performance.
title Mechanistic Understanding of Language Models in Syntactic Code Completion
topic Software Engineering
Artificial Intelligence
Computation and Language
I.2.7
url https://arxiv.org/abs/2502.18499