Looking into Black Box Code Language Models

Muhammad Umair Haider, Umar Farooq, A. B. Siddique, Mark Marron

TL;DR

This paper dives into the "black box" of code language models (code LMs) by focusing on their under-explored feed-forward layers, which hold most of the model's parameters. They reveal that these layers store syntactic and semantic information, and crucially, that specific concepts can be edited within these layers without harming overall performance, paving the way for better debugging and understanding of code LMs.

What Problem Does This Paper Address?

Code language models (like GitHub Copilot) are becoming indispensable tools for software development, capable of generating, completing, and editing code. However, most research has treated these models as "black boxes," focusing solely on improving their performance on benchmarks. This lack of understanding about their internal workings leads to challenges in debugging, potential security vulnerabilities, and difficulty in updating the models. While some work has explored attention layers, the feed-forward (FF) layers, which constitute two-thirds of a transformer model's parameters, have remained largely unexamined. This paper aims to demystify these FF layers, understanding what information they store, how it's organized, and whether it can be manipulated.

Methods

The researchers employed a multi-pronged approach to investigate the feed-forward layers of two state-of-the-art code LMs: Codegen-Mono (a monolingual model) and Polycoder (a multilingual model).

  1. Information Storage (RQ1): They identified "trigger examples" for each "key" (a component within the FF layers) by finding input sequences that maximally activated that key. By analyzing these triggers using regular expressions for specific concepts (like NumPy or Python slicing), they could infer what syntactic and semantic patterns each key was sensitive to.
  2. Concept Editing (RQ2): To test editability, they "masked" (zeroed out) the weights of keys identified as relevant to a specific concept of interest. They then evaluated the model's performance on tasks related to that concept and on unrelated tasks to assess the impact of the editing.
  3. Layer Agreement (RQ3): They measured how well the top predicted token from each layer aligned with the final predicted token of the entire model. This was done by transforming layer outputs into probability distributions and comparing their top predictions.
  4. Context Size Impact (RQ4): They repeated the layer agreement experiment but varied the input context size to see how it affected the alignment between layers and the final output.

Datasets

The study utilized a custom dataset comprising 5,000 code files each for Java, Go, and Python, sourced from active GitHub repositories with at least 50 stars. This dataset was curated to ensure quality and representativeness of popular programming paradigms. The models themselves (Codegen-Mono and Polycoder) were pre-trained on large, diverse datasets like The Pile, BigQuery, and BigPython, as described in their respective model papers.

Key Insights and Ideas

  • FF Layers as Semantic Databases: The feed-forward layers act as the model's memory, storing a rich hierarchy of information. Lower layers capture basic syntactic patterns (like keywords and n-grams), while higher layers encode more abstract concepts and complex semantics.
  • Editable Concepts: Crucially, specific concepts (like API calls) can be "edited" by masking the relevant keys in the feed-forward layers. This suggests that the knowledge within these layers is localized.
  • "Thinking" vs. "Predicting" Layers: Initial layers seem to act as "thinking" or processing layers, while later layers are more directly responsible for predicting the next token.
  • Context Matters: Smaller context sizes allow even earlier layers to make accurate predictions, but as context grows, the model increasingly relies on the more semantically rich information in later layers.
  • Polysemantic Keys: The researchers observed "polysemantic keys" – neurons that represent multiple, seemingly unrelated concepts. This adds complexity to interpretability and editing efforts.

Key Results

  • Information Storage: Lower FF layers capture syntactic patterns (e.g., keywords like "frame" or "assert"), while higher layers capture more abstract concepts (e.g., mathematical functions like np.sin, image processing concepts, or deep learning loss functions).
  • Concept Editing: Masking keys related to a specific API (like NumPy or PyTorch) led to a significant drop in performance for that specific API (e.g., accuracy dropping by ~10-30% in Table IX). However, the model's performance on other concepts remained largely unaffected, demonstrating localized editing.
  • Layer Agreement: Initial layers show very low agreement with the final model output, supporting the "thinking layer" hypothesis. Agreement increases significantly in later layers, especially in the last few, which are highly correlated with the final prediction.
  • Context Size Impact: With small context sizes, even initial layers can predict tokens accurately. However, as context size increases, only later layers can maintain high agreement with the final output, highlighting their role in understanding complex, long-range dependencies.

Limitations and Future Work

  • Polysemantic Keys: The presence of polysemantic keys makes precise editing challenging, as masking a key might inadvertently affect multiple concepts. The authors acknowledge that they did not mask these polysemantic keys, which might explain why performance didn't drop to zero.
  • Editing Scope: The current editing work focuses on masking. Future work could explore more nuanced editing techniques.
  • Model Dependence: Differences in agreement patterns between Codegen-Mono and Polycoder suggest that training methodology (monolingual vs. multilingual) influences layer behavior. Further investigation into these differences is warranted.
  • Broader Applicability: While the study demonstrates editing for specific APIs, extending this to more complex code structures and a wider range of concepts is a natural next step.

The paper concludes that these findings are crucial for developing more comprehensive understanding, debugging, and testing methodologies for code language models.

Summary updated

BibTeX
@inproceedings{haider2026looking,
  author = {Muhammad Umair Haider and Umar Farooq and A. B. Siddique and Mark Marron},
  title = {{Looking into Black Box Code Language Models}},
  booktitle = {ICSC},
  year = {2026},
  doi = {10.1109/icsc67292.2026.00011},
}

Loading related content...

Figure