Enabling Global, Human-Centered Explanations for LLMs:From Tokens to Interpretable Code and Test Generation

Dipin Khati, Daniel Rodriguez-Cardenas, David N. Palacio, Alejandro Velasco, Michele Tufano, Denys PoshyvanykarXiv 2025 · DOI

As Large Language Models for Code (LM4Code) transition from research novelties to daily developer tools, a critical question emerges: Can we trust them? While we have plenty of metrics to measure if a model generates correct code, we have very few ways to understand why it makes specific decisions.

A new paper, "Enabling Global, Human-Centered Explanations for LLMs," introduces CodeQ, a framework designed to bridge this gap by turning noisy, low-level token data into high-level, human-understandable reasoning patterns.

TL;DR

CodeQ is a framework that aggregates noisy, token-level model rationales into high-level programming concepts (like "loops" or "conditionals"). This enables a global, statistical view of model behavior, revealing that LLMs often rely on shallow syntactic patterns (like indentation) rather than deep semantic logic, frequently misaligning with human reasoning.

What Problem Does This Paper Address?

Current interpretability methods for LLMs are often "local" and "token-level." They might tell you that a specific token in the prompt influenced a specific token in the output, but for a developer, this is often just noise. Humans don't reason about code token-by-token; we think in terms of functions, loops, and logic.

Furthermore, local explanations don't scale. A developer can't look at 10,000 individual token-attribution maps to figure out if a model has a systemic bias. We need global explanations—statistical summaries that show how a model behaves across an entire dataset—to build justified trust or diagnose recurring flaws.

Methods

The authors introduce CodeQ, which follows a four-step pipeline to generate both local and global explanations:

  1. Constructing Testbeds: Curating diverse prompts for tasks like code completion and test generation.
  2. Pre-conditions: Fine-tuning models to be "compatible," meaning they can produce stable outputs even when given partial or masked inputs.
  3. The CodeQ Core:
    • Rationalization: Using a greedy algorithm to find the minimal subset of input tokens (rationales) that preserve the model's prediction.
  4. Mapping: Mapping these raw tokens to a hierarchy of human-centric categories (e.g., mapping if to [conditionals]).
  5. Reduction: Aggregating these mappings across thousands of samples into a global Interpretability Tensor ($\Phi$).
  6. Code Explanation: Visualizing the results through dependency maps (local) and heatmaps or frequency charts (global).
The CodeQ framework pipeline, moving from raw prompts to global interpretability tensors.

Datasets

The study evaluated two distinct model architectures:

  • Python Code Completion: Using codeparrot-small (decoder-only) on a testbed of 50,000 unique snippets mined via the Galeras tool.
  • Java Test Case Generation: Using BART-large (encoder-decoder) on the Methods2Test dataset (1,000 samples).
  • Human Alignment: A user study involving 37 participants (researchers and developers) to compare human reasoning against model rationales.

Key Insights and Ideas

  • Signal from Noise: Individual tokens are "weak" predictors. However, when aggregated into categories, the "signal strength" (probability) increases by roughly 6x.
  • The "Syntax Bias": The models studied are essentially master pattern-matchers of surface structure. They rely heavily on [structural] and [expression] categories (like indentation and punctuation) while consulting semantically rich logic like [loops] or [conditionals] far less often.
  • Reasoning Misalignment: There is a fundamental gap between how models and humans think. In the user study, the Jaccard similarity (a measure of overlap) between human-provided rationales and model-generated ones was strikingly low.
  • Adaptive Bootstrapping: When code is missing from a prompt (e.g., docstring-only), models dynamically "bootstrap" their reasoning, shifting from natural language cues to their own generated code tokens to maintain syntactic correctness.
Figure 4: Interpretability Concepts (C) for Java and Python

Key Results

  • Entropy Reduction: Aggregating tokens into concepts reduced explanation uncertainty (Shannon entropy) by over 50%, proving that the conceptual mapping distills a much clearer signal.
  • Global Reasoning Patterns: Heatmaps revealed that for test generation, models exhibit strong "self-reliance," where specific source concepts (like data types) are the primary drivers for generating the same concepts in the output.
  • User Validation: 89% of practitioners agreed that CodeQ could be useful for fine-tuning models, and 81% found it helpful for inferring causal relationships between input and output.
  • Quantitative Misalignment: The Jaccard similarity score for code completion was only 0.074, highlighting that the model's "reasons" for a prediction rarely match a human's.
Global heatmaps showing how source concepts influence target concepts in test generation.

Limitations and Future Work

  • Computational Complexity: The greedy rationalization process is $O(t \cdot p)$, which is computationally expensive for very large models or long sequences.
  • White-Box Requirement: The framework currently requires access to model weights and the ability to fine-tune for compatibility, which is a barrier for closed-source models like GPT-4.
  • Visualization UX: While the data was informative, participants found the graphical heatmaps somewhat difficult to read, suggesting a need for better HCI (Human-Computer Interaction) design.
  • Future Tooling: The authors propose developing CodeQ as a VS Code extension that provides "on-hover" natural language insights (e.g., warning a developer when a model is over-relying on a variable name rather than logic).

Summary updated

BibTeX
@misc{khati2025enabling,
  author = {Dipin Khati and Daniel Rodriguez-Cardenas and David N. Palacio and Alejandro Velasco and Michele Tufano and Denys Poshyvanyk},
  title = {{Enabling Global, Human-Centered Explanations for LLMs:From Tokens to Interpretable Code and Test Generation}},
  year = {2025},
  eprint = {2503.16771},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.16771},
}
Figure