Exploring XAI Methods for Interpretability of Large Language Models

SVG Icon Editor

Imagine asking an LLM to predict the sentiment of a movie review. How does it decide whether the tone is positive or negative? Large Language Models (LLMs), including transformer-based systems such as GPT-style models and BERT, have transformed natural language processing, allowing us to ask conversational agents to summarise text, answer questions, and classify sentiment. However, their impressive outputs can often feel opaque, leaving users and developers to wonder: why did the model make this prediction? This is where Explainable AI (XAI) steps in, offering tools to make model predictions more transparent. In this post, we will explore four key approaches to understanding the behaviour of LLMs.

Feature Attribution: Pinpointing Influential Inputs

One way to explain a model’s output is through feature attribution. These methods aim to identify which parts of the input, such as words or tokens, had the greatest influence on the model’s prediction. A common starting point is the attention mechanism, which is a foundational component of many LLMs.1 Attention weights can be visualised as heat maps, showing how strongly different tokens attend to one another during processing.

Figure 1 shows an example of how attention weights can be visualised. The input “query”, represented by a row token, is shown on the y-axis, and its attention weight is mapped to each “key/value” column token on the x-axis. Darker cells indicate stronger attention, meaning that the column token contributes more to updating the row token’s representation. The weights are typically normalised so that each row sums to approximately 1, making it easier to compare the relative strength of different connections.

Attention maps can provide a useful starting point for interpretation because they show which tokens the model is focusing on internally. However, they should be treated with caution: high attention does not always mean that a token caused the final prediction. For this reason, attention-based explanations are often most useful when combined with other XAI methods.

Example attention map showing token-to-token attention weights in a sentiment analysis task
Figure 1: Example of an attention map plot, showing how different tokens influence the model’s internal representation in a sentiment analysis task.

Post-Hoc Explanations: Decoding Predictions After the Fact

While attention maps use information from inside the model, post-hoc explanation methods analyse a prediction after it has been made. These methods are especially useful because they can often be applied without needing full access to the model’s internal architecture.

Important examples include model-agnostic tools such as SHAP2 and LIME3, which work by systematically perturbing the input and observing how the output changes. This allows us to estimate which tokens or features most influenced the prediction. If changing part of the input causes a large change in the output, this suggests that it had a strong impact on the model’s decision. Figure 2 shows an example of a LIME-style explanation, where the size of each bar corresponds to the influence of each word. In practice, this can reveal why an email was classified as spam, or why a customer support query was routed to a specific department.

Counterfactual analysis4 builds on a similar idea by asking: what is the smallest change to the input that would change the model’s output? For example, if switching “he” to “she” in a job application significantly alters the result, this may indicate bias in the system. Counterfactuals can therefore help identify whether a model is relying on sensitive or inappropriate features.

Example LIME explanation showing positive and negative word contributions for sentiment classification
Figure 2: Example of the LIME method for measuring feature importance in sentiment classification. The plot shows which words had the greatest impact on the model’s prediction, with blue bars indicating positive contributions and red bars indicating negative contributions.

Concept-Based Explanations: Linking Models to Human Ideas

LLMs do not simply process words one by one. They map text into high-dimensional mathematical representations that can capture relationships between words, phrases, and concepts. Concept-based explanations aim to connect these internal representations back to human-understandable ideas.

For example, a model might represent words such as “happy”, “joyful”, and “excited” in nearby regions of its internal representation space. This suggests that the model has learned a broader concept related to positivity. This idea is central to concept vectors,5 which allow researchers to test whether a model has encoded a particular concept and how strongly that concept influences its predictions.

Concept-based explanations can be especially valuable because they move beyond individual words and instead ask whether models are using higher-level ideas that make sense to humans. This can help researchers understand not only what a model predicts, but also what kinds of concepts may be shaping its behaviour.

Global Model Understanding: Seeing the Bigger Picture

Unlike feature attribution or concept-based explanations, which often focus on a specific prediction or concept, global interpretation methods aim to summarise a model’s overall behaviour across many inputs. These techniques help researchers identify broader patterns in how a model organises information.

However, the internal representations used by LLMs are usually high-dimensional, making them difficult to interpret directly. Dimensionality reduction methods such as t-SNE6 and UMAP7 offer a way to visualise these representations in two or three dimensions. For example, they can show whether texts with similar topics, writing styles, or sentiments cluster together, and where the model may be confusing one category with another.

Global analysis can also reveal how representations change from layer to layer, or whether the model makes recurring types of errors. In this way, global methods complement local explanations by providing a system-level view of model behaviour.

The Path Forward: Building Transparent AI

Interpreting LLMs is no simple task. Their size and complexity make explanations computationally challenging, and the explanations produced by XAI methods can sometimes be ambiguous or incomplete. Models may also appear confident even when their predictions are unreliable, which makes it important to interpret explanations carefully.

Explainable AI methods are helping us better understand LLMs by providing partial, task-specific insights into their behaviour. Taken together, feature attribution, post-hoc explanations, concept-based analyses, and global model understanding can make models less opaque and more trustworthy, even if full transparency remains an open challenge. As LLMs become increasingly important in fields such as healthcare, law, and education, the demand for interpretability will only grow. XAI is not just a tool for researchers; it is a foundation for building AI systems we can better understand, evaluate, and trust.

References

1. Vaswani, Ashish, et al. “Attention Is All You Need.” Advances in Neural Information Processing Systems (2017).

2. Lundberg, Scott M., and Su-In Lee. “A Unified Approach to Interpreting Model Predictions.” Advances in Neural Information Processing Systems (2017).

3. Ribeiro, Marco Tulio, Sameer Singh, and Carlos Guestrin. “Why Should I Trust You? Explaining the Predictions of Any Classifier.” Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, pp. 1135–1144, 2016.

4. Wachter, Sandra, Brent Mittelstadt, and Chris Russell. “Counterfactual Explanations Without Opening the Black Box: Automated Decisions and the GDPR.” Harvard Journal of Law & Technology 31 (2017): 841.

5. Kim, Been, Martin Wattenberg, Justin Gilmer, Carrie Cai, James Wexler, and Fernanda Viégas. “Interpretability Beyond Feature Attribution: Quantitative Testing with Concept Activation Vectors (TCAV).” International Conference on Machine Learning, pp. 2668–2677. PMLR, 2018.

6. van der Maaten, Laurens, and Geoffrey Hinton. “Visualizing Data Using t-SNE.” Journal of Machine Learning Research 9, no. 11 (2008).

7. McInnes, Leland, John Healy, and James Melville. “UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction.” arXiv preprint arXiv:1802.03426 (2018).


About the Author

Molly Kennedy, BA, MSc is a doctoral researcher specializing in Explainable AI for understanding and mitigating media bias in Large Language Models, under the supervision of Prof. Dr. Hinrich Schütze at the Chair for Computational Linguistics (LMU Munich). As a member of relAI, her work focuses on making AI-generated content more transparent, interpretable, and accountable.


RELATED

  • Can We Trust the Uncertainty of Causal Foundation Models?

    Causal foundation models promise fast, flexible treatment-effect estimation from observational data, but can their uncertainty be trusted? This post examines prior-data fitted networks (PFNs) for causal inference, revealing a hidden prior-induced confounding bias, and introduces a one-step posterior correction that restores reliable, frequentist-consistent uncertainty for average treatment effect estimation. Full post
  • Robotic Decision Making via Diffusion Models

    Robots are increasingly expected to operate in complex, real-world environments, but the machine learning methods that drive their decision-making, like reinforcement and imitation learning, often struggle with training stability and capturing the multimodal nature of behavior. This post introduces diffusion models as a powerful alternative for robotic decision making, explaining their core denoising mechanism and surveying their applications in several contexts. Full post
  • A Beginner’s Guide to Certifiable Robustness

    Machine learning models, such as ChatGPT and those used in autonomous driving, are becoming essential tools in our daily lives. However, the existence of "adversarial examples" demonstrates that these systems are not free from vulnerabilities. The post, introduces the concept of adversarial examples and discusses Certifiable Robustness, a methodology designed to combat them. Full post
  • Responsible Textual Generative Models (Part I): Generating Truthful Content

    This post introduces hallucination in large language models—why fluent outputs can still be wrong, what distinguishes intrinsic from extrinsic errors, and how training data, model design, inference, and alignment contribute. It surveys detection and mitigation approaches and sets up later posts on toxicity, bias, and inclusivity in responsible textual generative AI. Full post
  • Random Convolutions: A Simple Way to Boost Generalization

    Random Convolutions (RC) are a simple and effective data augmentation technique designed to improve the robustness of deep learning models, particularly in medical imaging. Instead of relying on fixed or learned filters, RC applies a small stack of randomly generated convolutional filters to input images during training. This introduces strong but controlled variations in image texture while preserving the underlying anatomical structure. By exposing models to a wide range of plausible appearance changes, Random Convolutions reduce overfitting to dataset-specific characteristics such as scanner type or acquisition protocol. In practice, RC acts as an implicit form of domain randomization, encouraging models to focus on stable, shape-based and contextual features rather than fragile texture cues. Despite its simplicity and low computational cost, RC has been shown to substantially improve generalization across institutions and imaging conditions in challenging tasks such as multiple sclerosis lesion segmentation. Full post
  • Neuromorphic Computing: A Brain-inspired Approach to Robot Intelligence

    This post offers a high-level walkthrough of neuromorphic computing, why it matters for energy-efficient robot intelligence, and how SNNs, event cameras, and neuromorphic chips fit together Full post
  • Introduction to Embodied Instruction Following

    This work explores how AI systems bridge the gap between understanding human instructions and performing real actions by learning through direct interaction with their environment. Full post
  • From Unlucky Strikers to Statistical Learning Theory

    Using the analogy of football striker, this post explains how statistical learning theory helps us understand when we can trust model predictions and empirical averages, highlighting the challenges of generalization in modern machine learning, especially with complex models like deep neural networks. Full post
  • Performative Prediction

    Machine learning systems are increasingly used to support decision-making processes. Yet, these systems do not merely reflect the world—they also reshape it. Once deployed, predictions can influence behaviors, alter policies, and redirect resources, creating feedback loops that change the very data-generating processes they aim to model. Full post
  • What even is differential privacy?

    A concise introduction to differential privacy which offers provably privacy guarantees for training machine learning models. Full post
  • Mitigating Domain shifts

    Adapting a deep neural network to unseen data and tasks is imperative these days, however access to target data is often available. Common target adaptation techniques including domain adaptation and generalization train for meaningful representations during source training. Recent paradigms such as Test-time training/adaptation focus on optimizing the source model on unseen data. To do so, they finetune the model on the streaming unsupervised data which is useful for practical scenarios. Moreover, these techniques can be applied to variety of tasks such as regression, classification and segmentation. Full post
  • A gentle introduction to uncertainty quantification

    Uncertainty Quantification (UQ) is considered indispensable for predictive models in safety-critical applications. Modern models, though high-performing, struggle with providing meaningful uncertainty estimates due to a number of reasons. Full post
  • Welcome to the relAI Blog

    Welcome to the relAI blog of the Konrad Zuse School of Excellence in Reliable AI (relAI). This blog will serve as a platform to share cutting-edge research and developments from our school, highlighting the significant strides we are making towards making AI systems safer, more trustworthy, and privacy-preserving. Full post