How Programming Concepts and Neurons Are Shared in Code Language Models

Amir Hossein Kargaran, Yihong Liu, François Yvon, Hinrich Schütze

TL;DR

This paper explores the internal "concept space" of code large language models (LLMs), revealing that models use English as a semantic pivot when translating between programming languages. It also maps out how neurons are shared across different coding languages, showing that syntax-level sharing happens in lower layers, while language-exclusive neurons reside at the very top.

What Problem Does This Paper Address?

State-of-the-art LLMs are trained on vast mixtures of natural language (like English) and multiple programming languages (PLs) like Python, Java, and C++. While we know they code exceptionally well, we don't fully understand how they organize these different languages internally.

Do they treat each PL as an isolated silo, or do they use a common "pivot" language to translate concepts? Can we find specific neurons dedicated to Python versus Java? The authors address these questions by peering into the intermediate layers of Llama-based models during code translation tasks to uncover how programming concepts and neurons are shared.

Methods

The authors employ three main interpretability techniques to dissect the models:

  1. Logit Lens: This technique applies the model's final "unembedding" matrix prematurely to intermediate, non-final layers. This allows researchers to see what tokens the model is "thinking of" mid-computation.
  2. MEXA (Cross-lingual alignment): A metric used to evaluate how closely the vector representations of different programming languages align within the model's hidden layers based on cosine similarity.
  3. LAPE (Language Activation Probability Entropy): A method to identify language-specific neurons in Feed-Forward Networks (FFNs). By calculating the entropy of neuron activations across languages, they can find neurons that activate exclusively for a single language and test the impact of "turning them off" (ablation) using perplexity (PPL) metrics.

The study evaluates two models from the Llama family: CodeLlama 7B and Llama 3.1 8B.

Datasets

The study utilizes three types of datasets:

  • Super-parallel PL dataset: A newly curated dataset containing 581 parallel code snippets across 7 PLs (C++, Java, Python, C#, JavaScript, PHP, C), derived from GeeksForGeeks. This ensures identical semantic structure and comments across languages.
  • Keyword dataset: Programming-specific keywords and built-ins for 22 PLs, alongside English keywords from PanLex.
  • Raw PL and English dataset: 50,000 files/articles each for 11 popular PLs (from the GitHub Code dataset) and English Wikipedia to evaluate raw neuron activations.

Key Insights and Ideas

  • The English Detour: When translating code (e.g., Java to Rust), the model doesn't map source directly to target. In the middle layers, it takes a detour through English and general PL keywords to process the underlying concept before mapping it to the specific target syntax in the final layers.
Figure 1: Illustration of logit lens (Nostalgebraist, 2020) applied to CodeLlama 7B for the task of translating a for loop from Java to Rust (showing only Rust loop here). The y-axis shows layers, the x-axis input to- kens, and color next-token probabilities (red: low, blue: high). Terms decoded in intermediate layers, such as interval, range, until, and ten, are not keywords in Java or Rust but belong to other PLs (Python, Go, Ruby) and English. In Rust, the .. syntax defines a range. The tokens until and through, which decode for the same position but with lower probabilities or in earlier layers, share similar semantics with this syntax.
  • C# as a Central Hub: C# and C++ exhibit exceptionally high cross-lingual alignment with other PLs. Because they share large keyword sets and structural paradigms with many languages, they sit closer to the model's abstract concept space regardless of the input/output language.
  • Layer-wise Specialization: General language-specific neurons cluster at the very bottom layers (handling basic syntax), but neurons strictly exclusive to a single PL live at the very top layers, right where token generation happens.
Distribution of language-exclusive neurons across layers

Key Results

  • Token Probability Spikes: Logit lens tracking shows that token probabilities for English and general PL keywords spike around layer 15 (the halfway point for a 32-layer model) before the target PL tokens dominate in the final layers.
  • High Intermediate Alignment: Using MEXA, the authors found that alignment scores steadily increase across intermediate layers, peaking near an average of 0.9 right before the final output layer, proving the existence of a shared concept space.
  • The Challenge of Isolation: Ablating (deactivating) language-specific neurons in Llama 3.1 8B significantly increased perplexity for the target language while leaving other languages unaffected. However, for highly aligned languages like C# and Java, isolating these neurons was nearly impossible because their representations are so deeply shared across the network.

Limitations and Future Work

  • Language Constraints: The super-parallel dataset is limited to 7 programming languages due to data availability constraints.
  • Keyword Proxy: Using keyword matching to interpret latent embeddings is an imperfect proxy; a precise dictionary mapping PL keywords directly to semantic English equivalents would be ideal but is highly challenging to construct.
  • Architecture Scope: The study focuses exclusively on Llama-based architectures; future work should validate if these structural patterns hold true across other model families (such as GPT or DeepSeek).

Summary updated

BibTeX
@inproceedings{kargaran2025how,
  author = {Amir Hossein Kargaran and Yihong Liu and François Yvon and Hinrich Schütze},
  title = {{How Programming Concepts and Neurons Are Shared in Code Language Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure