Abstract
Code-trained language models have proven to be highly effective for various code intelligence tasks. However, they can be challenging to train and deploy for many software engineering applications due to computational bottlenecks and memory constraints. Implementing effective strategies to address these issues requires a better understanding of these 'black box' models. In this paper, we perform the first neuron-level analysis for source code models to identify important neurons within latent representations. We achieve this by eliminating neurons that are highly similar or irrelevant to the given task. This approach helps us understand which neurons and layers can be eliminated (redundancy analysis) and where important code properties are located within the network (concept analysis). Using redundancy analysis, we find that over 95% of the neurons are redundant with respect to our code intelligence tasks and can be eliminated without significant loss in accuracy. Through concept analysis, we trace individual and subsets of important neurons to specific code properties and identify 'number' neurons, 'string' neurons, and higher-level concepts. This helps us understand how decomposable and transferable task-related features are and can help devise better techniques for transfer learning, model compression, and the decomposition of deep neural networks into modules.
Introduction
Large Language Models (LLMs) trained on source code, such as CodeBERT and GraphCodeBERT, are powerful tools for software engineering. However, their massive size creates computational bottlenecks, and their "black box" nature makes them difficult to trust in security-critical areas like vulnerability detection. This paper addresses the need for fine-grained interpretability to guide model compression and knowledge transfer.
Methodology
The researchers adapted neuron-analysis techniques from NLP to the domain of source code. Their workflow involved extracting token and sentence representations to perform various tasks, followed by applying analysis techniques to identify redundancy and key concepts.
Key techniques included:
- Linguistic Correlation Analysis (LCA): Ranking neurons by task importance.
- Correlation Clustering (CC): Grouping neurons with similar firing patterns to identify redundancy.
- Selectivity-Guided Probing: Filtering out deterministic tokens (like punctuation) to ensure probes learn meaningful code properties.
- Centered Kernel Alignment (CKA): Measuring similarity between layers to identify redundant stages of processing.
Key Findings: Massive Redundancy
The most striking result is that over 95% of neurons are redundant for specific tasks. In some cases, pruning these neurons actually improved performance. For instance, RoBERTa saw a 5% accuracy increase in Defect Detection after neuron reduction, suggesting that pruning can remove harmful noise.
Furthermore, models often learn complex concepts in surprisingly shallow layers. GraphCodeBERT achieved baseline accuracy for Code Search using only its first two layers, indicating that high-level semantic features are extracted much earlier than previously thought.
Layer Similarity and Architecture
CKA analysis revealed that adjacent layers in many models are highly correlated, particularly in decoder-based generative models like CodeGPT.
As shown in the heatmaps above, the high similarity between layers (indicated by the bright diagonal and surrounding blocks) suggests significant potential for "layer-dropping" during model compression.
Concept Analysis
The study successfully traced individual neurons to human-recognizable concepts. They identified "monosemantic" neurons—those that do exactly one thing, such as a "number neuron." However, they also observed "superposition," where "polysemantic" neurons activate for multiple unrelated concepts. Disentangling these is a major hurdle for perfect interpretability.
Conclusion
This neuron-level "autopsy" provides a roadmap for creating smaller, more interpretable models. By identifying which neurons are essential and which are redundant, researchers can develop more efficient strategies for model compression and modular decomposition. Future work will focus on scaling these techniques to frontier models with billions of parameters.
Summary updated