Precise and Interpretable Editing of Code Knowledge in Large Language Models

Min Xue, Nikolai Bolik, Lennart Stöpler, Erik Imgrund, Janik Schmid, Artur AndrzejakICLR 2026

TL;DR

Researchers have developed TCPE (TransCoder-based Precise Editing), a method that allows for "surgical" updates to a Large Language Model's (LLM) code knowledge without breaking unrelated functions. By replacing standard model layers with sparse "TransCoders," they can identify and edit individual neurons that represent specific concepts (like a .length property). This approach improved Java-to-D translation accuracy from 57.5% to 64.0% with minimal data, all while maintaining model stability.

The Challenge of Editing Frozen Models

Large Language Models are essentially frozen in time once trained. If an API changes or the model consistently makes a specific coding error, developers typically face three suboptimal choices:

  1. Retrain/Fine-tune: Prohibitively expensive and requires massive datasets.
  2. Prompt Engineering: Temporary, fragile, and consumes valuable context window space.
  3. Knowledge Editing (KE): Directly modifying model weights to inject a specific fact or correction.

While Knowledge Editing holds promise, current methods (like ROME or MEMIT) target the model's Multi-Layer Perceptrons (MLPs). MLP neurons are notoriously "polysemantic"—meaning a single neuron might simultaneously process Python syntax, historical facts, and French grammar. When you edit these tangled neurons, you risk "model collapse" or unintended side effects. Furthermore, it becomes nearly impossible to explain why an edit worked or failed because the internal representations are so opaque.

Introducing TCPE: TransCoder-based Precise Editing

To solve the polysemanticity problem, the authors introduce TransCoder-based Precise Editing (TCPE). The core innovation involves swapping out a standard MLP layer for a TransCoder.

Architecture of TransCoder-based Precise Editing (TCPE), illustrating the replacement of an MLP layer with a TransCoder and the targeted updating of active neurons.
  • The TransCoder: This is an MLP-like component designed to be "wide and sparse." It uses an encoder-decoder structure trained with a sparsity loss (L1 regularization). This forces the model to use only a few neurons for any given input.
  • Monosemanticity: Because the activations are sparse, individual neurons tend to represent single, human-understandable concepts (monosemanticity), making them highly interpretable.
  • The Edit: When the model makes a translation error, TCPE identifies the tiny fraction of TransCoder neurons active during that specific error. It then performs a "rank-one update" (similar to the ROME method) but restricts the changes only to those specific active neurons.
  • Interpretability: Because the neurons are monosemantic, researchers can generate "feature dashboards" showing exactly what code snippets trigger a specific neuron, making the editing process entirely transparent.

Datasets and Evaluation

The paper introduces a new benchmark alongside existing ones to rigorously test this method:

  • KECode / G4GD (New): A benchmark specifically designed for code-to-code translation. It contains 600 Java functions to be translated into D (a low-resource language where LLMs often struggle). Crucially, each function includes 10 unit tests to verify "functional equivalence"—checking if the code actually works, not just if the text looks similar.
  • HumanEval: Used to ensure that editing the model to fix one error doesn't destroy its general coding ability.
  • CounterFact & zsRE: Standard NLP knowledge editing benchmarks used to prove the method works for general facts, not just code.

Key Insights

  • Surgical vs. Sledgehammer: While traditional KE methods might update over 11,000 neurons to fix a single fact, TCPE often updates fewer than 70. This extreme localization prevents the model from "forgetting" unrelated knowledge.
  • Functional Equivalence is the North Star: In natural language, verifying "The capital of France is Paris" is straightforward. In code, there are countless ways to write a valid loop. By using unit tests via KECode, the authors move evaluation beyond mere "textual similarity" to true "functional correctness."
  • The "Aha" Moment for Interpretability: The authors found that active neurons during an error were directly linked to the syntax causing the problem (e.g., neurons that specifically fire on .length calls or closing brackets }). Inactive neurons, by contrast, fired on irrelevant structural tokens.

Key Results

TCPE demonstrates significant improvements over existing state-of-the-art methods across multiple metrics.

Performance comparison of various Knowledge Editing methods, showing TCPE achieving the highest overall scores and reliability.
  • Accuracy Boost: On the Java-to-D translation task, TCPE improved CodeLlama-7b-Instruct's accuracy from 57.5% to 64.0%.
  • Superior Specificity and Reliability: TCPE significantly outperformed baselines like ROME, MEMIT, and LoRA. In HumanEval tests, TCPE maintained 100% reliability, meaning the edits did not degrade the model's baseline coding capabilities, whereas other methods saw noticeable performance drops.
  • Efficiency: The TransCoder adapter can be integrated into a model in seconds, and training the TransCoder itself takes only about 2 hours on a single H100 GPU.

Limitations and Future Work

While highly effective, TCPE has a few constraints:

  • Architectural Requirements: TCPE requires modifying the model's architecture by replacing an MLP with a TransCoder. This is impossible for closed, "black-box" models like GPT-4 or Claude.
  • Scaling Edits: The study focused on single and multi-error scenarios but has yet to explore how the model behaves after thousands of cumulative edits.
  • Language Scope: While Java-to-D is an excellent "low-resource" test case, future work must determine if these monosemantic neurons are as easily isolated in high-resource pairs like Python-to-C++.
  • Optimization Complexity: Integrating TransCoders increases the number of parameters in that specific layer (due to the "wider" hidden vector), which could introduce latency if scaled to every layer of the model.

Summary updated

BibTeX
@inproceedings{xue2026precise,
  author = {Min Xue and Nikolai Bolik and Lennart Stöpler and Erik Imgrund and Janik Schmid and Artur Andrzejak},
  title = {{Precise and Interpretable Editing of Code Knowledge in Large Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=diVf17SNek},
}
Figure