Beyond Syntax: How Do LLMs Understand Code?
Authors:
- 27 April 2025
- conference paper
- Published by Institute of Electrical and Electronics Engineers (IEEE)
- p. 86-90
Abstract
Within software engineering research, Large Language Models (LLMs) are often treated as ‘black boxes’, with only their inputs and outputs being considered. In this paper, we take a machine interpretability approach to examine how LLMs internally represent and process code.We focus on variable declaration and function scope, training classifier probes on the residual streams of LLMs as they process code written in different programming languages to explore how LLMs internally represent these concepts across different programming languages. We also look for specific attention heads that support these representations and examine how they behave for inputs of different languages.Our results show that LLMs have an understanding — and internal representation — of language-independent coding semantics that goes beyond the syntax of any specific programming language, using the same internal components to process code, regardless of the programming language that the code is written in. Furthermore, we find evidence that these language-independent semantic components exist in the middle layers of LLMs and are supported by language-specific components in the earlier layers that parse the syntax of specific languages and feed into these later semantic components.Finally, we discuss the broader implications of our work, particularly in relation to concerns that AI, with its reliance on large datasets to learn new programming languages, might limit innovation in programming language design. By demonstrating that LLMs have a language-independent representation of code, we argue that LLMs may be able to flexibly learn the syntax of new programming languages while retaining their semantic understanding of universal coding concepts. In doing so, LLMs could promote creativity in future programming language design, providing tools that augment rather than constrain the future of software engineering.Keywords
This publication has 6 references indexed in Scilit:
- Code Gradients: Towards Automated Traceability of LLM-Generated Code2024
- Is it harmful or helpful? Examining the causes and consequences of generative AI usage among university studentsInternational Journal of Educational Technology in Higher Education, 2024
- The Consequences of Generative AI for UGC and Online Community EngagementSSRN Electronic Journal, 2023
- How do developers discuss and support new programming languages in technical Q&A site? An empirical study of Go, Swift, and Rust in Stack OverflowInformation and Software Technology, 2021
- On the Dangers of Stochastic Parrots2021
- Transformer Feed-Forward Layers Are Key-Value Memories2021