Abstract
Large Language Models (LLMs) have demonstrated remarkable capabilities across diverse tasks, yet their black-box nature raises concerns about transparency and faithfulness. Input attribution methods aim to highlight each input token's contributions to the model's output, but existing approaches are typically model-agnostic, and do not focus on transformer-specific architectures, leading to limited faithfulness. To address this, we propose Grad-ELLM, a gradient-based attribution method for decoder-only transformer-based LLMs. By aggregating channel importance from gradients of the output logit with respect to attention layers and spatial importance from attention maps, Grad-ELLM generates heatmaps at each generation step without requiring architectural modifications. Additionally, we introduce two faithfulneses metrics $\pi$-Soft-NC and $\pi$-Soft-NS, which are modifications of Soft-NC/NS that provide fairer comparisons by controlling the amount of information kept when perturbing the text. We evaluate Grad-ELLM on sentiment classification, question answering, and open-generation tasks using different models. Experiment results show that Grad-ELLM consistently achieves superior faithfulness than other attribution methods.
Introduction
As Large Language Models (LLMs) are increasingly deployed in high-stakes domains such as healthcare and finance, understanding their decision-making process becomes critical. Explainable AI (XAI) addresses this through "input attribution"—the process of assigning scores to input tokens based on their influence on the final output. However, most existing attribution methods, such as Integrated Gradients or LIME, are often model-agnostic or designed for older encoder-only architectures like BERT. When applied to modern, autoregressive, decoder-only LLMs (e.g., Llama, Mistral), these methods can be computationally expensive and often fail to accurately reflect the model's internal reasoning, a property known as "faithfulness."
Furthermore, current evaluation metrics for these explanations are often flawed. Metrics using "soft perturbations" (randomly dropping words based on importance scores) can be biased. If one method generates higher average scores than another, the evaluation may leave more words in the sentence for that method, artificially inflating its performance.
Methodology: Grad-ELLM
To address these challenges, we propose Grad-ELLM, a gradient-based attribution method tailored specifically for the architecture of decoder-only LLMs. Grad-ELLM calculates attribution scores at each generation step by aggregating two internal signals:
- Channel Importance: Derived from the gradients of the output logit with respect to the attention layers.
- Spatial (Token) Importance: Derived from a "loosened" attention map. Standard softmax attention is often too sparse; loosening it helps reveal unattended tokens that contain similar, highly relevant information.
Crucially, Grad-ELLM generates these explanations without requiring architectural modifications or multiple expensive forward passes, making it efficient for large-scale models.
Fairer Evaluation with $\pi$-Soft Metrics
We also introduce $\pi$-Soft-NC and $\pi$-Soft-NS, which are modifications of existing soft-perturbation metrics. These metrics apply a mathematical transformation to attribution scores before testing, ensuring that the expected number of retained words is identical across all compared methods. This allows for a rigorous "apples-to-apples" comparison of explanation quality by controlling for the amount of information ($\pi$) kept during perturbation.
Experimental Evaluation
We evaluated Grad-ELLM across several tasks and datasets:
- Sentiment Classification: IMDb and SST2.
- Question Answering & Generation: BoolQ, TellMeWhy, and WikiBio.
The models used for evaluation included Llama and Mistral. We compared Grad-ELLM against several baselines, including random attribution, attention maps, saliency, and integrated gradients.
Results and Discussion
Grad-ELLM consistently demonstrated superior faithfulness compared to existing methods. Quantitative results using the $\pi$-Soft-NS metric show that Grad-ELLM achieves the highest Area Under the Curve (AUC) across various datasets.
Key insights from our evaluation include:
- Architecture-Specific Advantages: By leveraging the specific attention and gradient structures of decoder-only transformers, Grad-ELLM extracts more accurate reflections of model reasoning than model-agnostic methods.
- Metric Fairness: The use of $\pi$-controlled metrics revealed that previous benchmarks inadvertently favored methods with higher average scores.
- Contextual Nuance: Qualitatively, Grad-ELLM produces denser, more holistic heatmaps. For instance, in sentiment analysis, while baselines might fixate on a single word like "positive," Grad-ELLM correctly identifies the entire phrase "very little positive" as the driver of a negative sentiment. It also successfully captures non-traditional drivers like emojis or numerical ratings (e.g., "10/10").
Conclusion and Future Work
Grad-ELLM provides a faithful and efficient explanation method for modern LLMs. While it requires "white-box" access to internal model states—limiting its use on closed-source APIs—it offers a significant step forward for transparent AI. Future work includes extending Grad-ELLM to multimodal LLMs, integrating it into bias mitigation pipelines, and further refining the attention-loosening mechanism for even larger architectures.
Summary updated