Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Explainable AI

Explanations were defined and characterised in explanations. This post explores the connection of explanations to deep learning models.


Model Explainability

Explainable AI (XAI) is primarily about explaining machine and deep learning models and their outputs. In this blogpost, explainability and interpretability are considered synonyms. Model explainability can be defined as:

The degree to which we can answer questions a model's predictions and inner workings. The answers are context and audience (including ourselves).

Another definition is found in "Why Should I Trust You?":

By "explaining a prediction", we mean presenting textual or visual artifacts that provide qualitative understanding of the relationship between the instance's components (e.g. words in text, patches in an image) and the model's prediction.

Below, a few types of model explainability, namely Intrinsic and Extrinsic1, Local and Global, are explained. The quote just above is closer to our "Extrinsic Explainability".

Global and Local Explanations

  • Global: valid for all inputs (explains the model) e.g. by combining local explanations.
  • Local: for specific inputs-outputs.

Intrinsic Explainability

Looks at the internal mechanics, at the roles of layers, neurons, weights; it may also relate to constraining the model in form (e.g., Rudin C. or Zachary C.) —that is, imposing physical constraints, inductive biases, causal inputs selected by experts, monotonicity, sparsity, constraining model size or computational complexity. Or as Zachary C. puts it:

Sufficiently high-dimensional [linear] models, unwieldy rule lists, and deep decision trees could all be considered less transparent than comparatively compact neural networks.

Transparency is domain-dependent. For example, the field of geometric deep learning can express constraints (or inductive biases) of connectivity related to molecules and materials (e.g. GNNs), making them more interpretable than other network architectures for representing this particular input / physical problem. This can be further extended to symmetry and other aspects.

Extrinsic Explainability

From Zachary's paper:

(...) opaque models can be interpreted after the fact, without sacrificing predictive performance.

This is what this post calls Extrinsic Explainability.

On top of the previous quote, the paper "Why should I trust you?" has an explainer desiderata: it should give a qualitative understanding between inputs and outputs, be easy to understand, and be model agnostic and locally faithful (a good fit to the original model in the vicinity of the instance being explained). In that paper, SP-LIME combines local explanations to provide a global explanation of the model.

Rudin argues that these simpler explanation models2 must be wrong. If it is perfectly accurate, then we don't need the original model. Rudin proposes calling these model-approximation techniques "summary of predictions", "summary statistics" or "trends".

On the other hand, methods such as SHAP, LIME, t-SNE, can provide some understanding of the model, even if using approximations. Some of those popular methods are explained in strategies.

Brief Aside: Neural Netwoks

This post assumes a working idea of what deep learning models or neural networks are. A simple definition is provided in the paper Can we open the black box of AI? (Section "Good Trip").

But what exactly do these networks learn? "Scientific discovery in the age of artificial intelligence" states that:

[AI methods] includes deep representation learning (Box 1), particularly multilayered neural networks capable of identifying essential, compact features that can simultaneously solve many tasks that underlie a scientific problem.

So a key aspect of understanding and explaining will be to decode those "essential, compact features" into domain concepts. What concepts, if any, are stored there, in the synapses?

It's also useful to have in mind a general idea of where are neural networks models being used, and how:

  1. Domain-specific (Narrow AI): these are small or large models but trained on a specific domain (protein folding, generating new molecules, predicting spectra and so forth). These models benefit from XAI, inductive biases and constrains, and would ideally be interpretable.
  2. Domain-general (Foundation Models): there is a spectrum between networks trained for a task in a domain, and for a whole domain (e.g. chemistry). These models are usually very large, pre-trained in some unsupervised way and then need to be fine tuned to specific tasks, where they reuse the learnt building blocks.
  3. AI agents: These are clusters of models working together to carry out many parts of the scientific process of discovery (hypothesis generation, reading literature, suggesting experiments and running code simulations etc.) In some cases they may also have access to robotics platforms and run real world experiments. The difference to other approaches is that these models are reasoning, and to some extent work like a team of scientists.

Here we are concerned with 1. primarily, and with the possibility to explain them, design them such that they are interpretable and finally understand them better.

Trade-offs?

We may expect model explainability to be inversely correlated with model complexity or accuracy. Graphically:

Model Explainability vs Model accuracy tradeoff.

Hypothesis: Model explainability v. Accuracy tradeoff.

And in "Why Should I Trust You?" (refs removed):

Recognizing the utility of explanations in assessing trust, many have proposed using interpretable models, especially for the medical domain. While such models may be appropriate for some domains, they may not apply equally well to others (...). Interpretability, in these cases, comes at the cost of flexibility, accuracy, or efficiency.

And in [SHAP][shap]:

However, the highest accuracy for large modern datasets is often achieved by complex models that even experts struggle to interpret, such as ensemble or deep learning models, creating a tension between accuracy and interpretability.

Other researchers such as Rudin disagre (bold is mine, references were removed):

Two obstacles to using interpretable models are that they are harder to optimize because they require extra constraints, and there is an incorrect perception that they are less accurate than black boxes. On the first point, the community is getting quite good at building interpretable sparse models and interpretable neural networks. On the second point, there is no scientific evidence that accuracy must be sacrificed when adding interpretability constraints.

Rudin's more detailed paper states something similar:

There is a widespread belief that more complex models are more accurate, meaning that a complicated black box is necessary for top predictive performance. However, this is often not true, particularly when the data are structured, with a good representation in terms of naturally meaningful features.

I'd make two comments to the quote above. First, good representation in terms of naturally meaningful features may be hard to obtain or create. Second, NNs tend to perform better as we scale them up. Though there is some "optimal-size region" and going beyond could plateau or even decrease its performance.

For complex tasks (Natural Language Processing, Computer Vision), DL models surpass most other algorithms. For narrower tasks, it is sometimes possible to find interpretable models that are also very accurate (benchmarks?), but they can be very hard to design, making the time-risk-benefit tradeoff worth considering:

Interpretable models can entail significant effort to construct, in terms of both computation and domain expertise. (...) for high-stakes decisions, analyst time and computational time are less expensive than the cost of having a flawed or overly complicated model. (...) The researcher needs to create a model that has the capability of uncovering the types of patterns that the user would find interpretable, but also the model needs to be flexible enough to fit the data accurately. This, and the optimization challenges discussed above, are where the difficulty lies with constructing interpretable models.

Out of Distribution

Consider an imaginary model , being the model, being the proportion of people with an umbrella and the probability of rain. The model reaches low evaluation error and everyone is happy.

However, the model consistently fails to predict rains when people didn't take the umbrella. Why could this happen? Some of the reasons below were inspired by the paper "The Mythods of Model Interpretability":

  1. The model undefitted the data, and we may need a better model.
  2. The dataset is not representative the deployment environment, and the model can't generalise out of training distribution. Can it be fixed if we don't have those datapoints? Were there simply wrong datapoints, that led the model in the wrong direction? Can we create synthetic data?
  3. The approach itself was incorrect: we use variables that promote association rather than causation.

Selecting possible causal variables, such as pressure and temperature, rather than the fraction of humans carrying out an umbrella, could help to make it more accurate, and even more explainable. But does it have all the causal inputs? Why do we expect it to work out of distribution, though?3

A subset of causal-variables may do for a good-enough approximation, and even generale well out of distribution. In some cases though, it may be enough to have a correlation model, but they should be distinguished.

Selecting those variables is not very easy, though. An expert must pick known causes-effects pairs as inputs-outputs to train a model, but others may unknowingly build a correlation model instead.

It is hard to predict whether a model will work out of distribution without knowing what it has learnt. Knowing what a model has learnt is part of the XAI discipline, both opening the box, or carefully comparing its outputs.

Similarly, this two-page comment by Cynthia Rudin highlights the preference for interpretable (transparent) models in high stakes scenarios.

In Deep Learning Models, the problem constraints can be used to add inductive biases or priors to architectures, such as symmetry constraints, connectivity (say through graph networks). This may also reduce the amount of training data needed, improve generalisation and improve interpretability.

An idea related to "Out Of Distribution" inference is that of "Transfer Learning": If a model has learnt "essential, compact features" then they should generalise to other task, as stated in Scientific discovery in the age of artificial intelligence (references where removed):

Self-supervised learning (Box 1) has enabled neural networks trained on labelled or unlabelled data to transfer learned representations to a different domain with few labelled examples, for example, by pre-training large foundation models and adapting them to solve diverse tasks across different domains.

This is especially useful when models can leverage large amount of data, which is usually in the form of unlabelled data (there are also mechanisms to label data semi-reliably).

Another promising path towards better generalisation is that of Causal AI. As "Scientific discovery in the age of artificial intelligence" puts it:

Although many scientific laws are not universal, their applicability is generally broad. Compared with state-of-the-art AI, human brains can better and faster generalize to modified settings. An attractive hypothesis is that this is because humans build not just a statistical model of what they observe but a causal model, that is, a family of statistical models indexed by all possible interventions (for example, different initial states, actions of agents or different regimes). Incorporating causality in AI is still a young field

Model Insights from Comparisons

How many ways do we have to make comparisons? Probably dozens. Analogies, metaphors, counterfactuals, a reference case (opposite or similar), a prototype or class-assignment (generalisation uses comparison).

Counterfactuals What would have happened with an alternative input (a hypothetical case counter to the fact). It's most informative to use the minimum changes that change an output class. They are also similar to What ifs (as the question shows).

Counterfacturals and other comparisons can help to explain models without opening the box.

For a model, counterfactuals are yet another inference from another input, but the comparison is helpful because that is one way humans understand things. We can use them as a proxy to "understand how the model is thinking" (that is, by comparing results or inferences).

In a similar fashion to counterfactuals, we can compare with reference inputs.

Overview of methods

There are many methods to identify causes or relevant properties on models, that help explain how they work. Some of them include counterfactuals and comparison, in the same sense as used in our previous section.

For all audiences, we can group these methods into more general categories, and then go into specific cases for a certain audience.

Kinds of Methods

The survey Principles and practise of explaining ML models includes a table of method kinds. A modified version of the table is below:

KindAdvantagesDisadvantagesQuestion
Local explanationsExplains the model's behaviour in a local area of interest. Operates on instance-level explanations.Explanations do not generalize on a global scale. Small perturbations might result in very different explanations.How do small perturbations affect the output / prediction?
ExamplesRepresentative items for each class provide insights about the model's internal reasoning.Examples require human selection. They do not explicitly state what parts of the example influence the model.How do inputs from different classes compare? And same?
Feature relevanceThey operate on an instance level (some can operate globally).Methods may make assumptions which do not hold (e.g. feature independence, linearity).Which input features are most important?
SimplificationSimple surrogate models explain opaque ones.Surrogate models may not approximate original models well.Can we get local insights by using a simpler model?
VisualizationsEasier to communicate to non-technical audiences. Most approaches are intuitive and not hard to implement.There is an upper bound on how many features can be considered at once. Humans must inspect plots to derive explanations.Class boundaries?

A method not listed there are text explanations, which can be generated from an RNN or a language model, reading the model's internal state (for example, this can generate captions).

We should remember that:

Relying on only one technique will only give us a partial picture of the whole story, possibly missing out important information. Hence, combining multiple approaches together provides for a more cautious way to explain a model. (...) At this point we would like to note that there is no established way of combining techniques (in a pipeline fashion),

In the next posts, we focus on methods that aid causal attribution (or cognitive process) with a scientific audience in mind.

Map of XAI

An interesting map of XAI is given in the survey Principles and practice of explainable ML (2021).

Most classic ML models are in the dashed area under Model types column.

Classic ML models are usually transparent (intrinsically explainable) but may benefit from post-hoc (post training) explanations, such as visualising it. When transparency is key and the predictions are accurate enough, these may be preferred over DL models.

Complex Graph linking prediction models such as SVMs, kinds of explanations such as text or graph, and explanation methods such as SHAP.

Image from paper under CC-BY

To the visual explanations, t-SNE, PCA and other dimensionality reduction techniques can be added.

The focus here though, is explaining deep learning models which are often, but not always, more accurate than classic ML models.


Sources
  1. Can we open the black box of AI? (2016). This paper briefly explains what ANNs are, their similarities (not the differences) to the brain, and what challenges they pose to us. Primarily, the challenge is that they are hard to explain. It puts as an example a physician or patient relying in the output, but not knowing why it predicts that. The author also cites Michael Tyka saying "The problem is that the knowledge gets baked into the network, rather than into us" which is also interesting. Furthermore, there isn't a "number 5 pattern" that is the same for many networks; the pattern appears from the training procedure, and although it may be similar for all number 5, it's usually different between training runs, datasets, and networks. Similarly so for brains!

  2. "Why Should I Trust You?": Explaining the Predictions of Any Classifier (2016)

  3. The Mythos of Model Interpretability (2018) is an excellent break down of ideas. They consider two interpretability strategies:

    • Transparency (intrinsic explainability) can refer to: 1. simulatability i.e. can mentally run the model, 2. decomposability i.e. each part of the model admits an intuitive explanation, and 3. algorithmic training which focuses on global vs local minimum, error and loss, guaranteed convergence.;
    • Posthoc interpretability (black boxness / extrinsic explainability): does not elucidate precisely how a model works. It breaks down techniques such as 1. Textual explanations using RNNs, visual explanations of learned representations (dimensionality reduction methods such as t-SNE, PCA), input alteration (to maximise activation of a neuron), 2. Local alterations using derivative of input wrt output (measuring "sensitivity" to each pixel); 3. By example / similarity / comparison and so forth. Posthoc is the sort of interpretability / explainability that applies to humans (which are otherwise black boxes).
    • Another takeaway is that obsessing about model transparency can harm accuracy and capability of a model, so it is important to consider this aspect.
  4. A Unified Approach to Interpreting Model Predictions (2017): paper proposing SHAP, that is, showing Shapley values as the best coefficients in linear combination of features, given 3 requirements (local accuracy, missingness and consistency),

  5. Explaining Explanations: An Overview of Interpretability of Machine Learning (2018),

  6. Producing radiologist-quality reports for interpretable artificial intelligence (2018): a "case study",

  7. The Book of Why (2018): The introduction and first chapter were read in detail, only the part of interest for XAI (to my judgement) is discussed here, comparison and counterfactuals. It's interesting but may be more useful in other areas (like medical sciences, economics etc.)

  8. Stop Explaining Black Box Machine Learning Models for High Stakes Decisions and Use Interpretable Models Instead (2019).

    • Suggests post-hoc models are worse than interpretable/transparent ones for high-stakes scenarios. It also states that the definitions of "Interpretable" varies for each field (references removed):

    Interpretability is a domain-specific notion, so there cannot be an all-purpose definition. Usually, however, an interpretable machine learning model is constrained in model form so that it is either useful to someone, or obeys structural knowledge of the domain, such as monotonicity, causality, structural (generative) constraints, additivity, or physical constraints that come from domain knowledge. Interpretable models could use case-based reasoning for complex domains.

    • The paper also challenges the beliefs that 1. There is a trade-off between interpretability and accuracy; also that 2. Explanation models (e.g. SHAP, LIME) provide faithful explanations of black-box models (and that a better term to "explanations" is "summary statistics" or "trend"), finally that 3. The explanations are detailed enough (Saliency Maps) and so forth.
    • And describes challenges towards Interpretable AI: 1. Black boxes shields companies from accountability (incentives); 2. Interpretable models are harder to construct (require more expertise). 3. Belief DL models can uncover patterns that interpretable models wouldn't find (the issue is the belief).
  9. The perils and pitfalls of explainable AI: Strategies for explaining algorithmic decision-making (2021): emphasis on socio-political aspects,

  10. Why black box machine learning should be avoided for high-stakes decisions, in brief (2022),

  11. Interpretable and Explainable Machine Learning for Materials Science and Chemistry (2022),

  12. Principles and practice of explainable machine-learning (2021, 25 pages): Sections 8–11 are a useful review of explainability methods.

  13. Scientific discovery in the age of artificial intelligence (2023).

  14. A Perspective on Explainable Artificial Intelligence Methods: SHAP and LIME (2024).


  1. Intrinsic explainability is also called "Transparency", "Inherently interpretable models"; Extrinsic explainability is also called "black boxedness", post-hoc explainability, opaqueness.

  2. In their words : "We introduce the perspective of viewing any explanation of a model’s prediction as a model itself, which we term the explanation model." and also "Instead, we must use a simpler explanation model, which we define as any interpretable approximation of the original model.".

  3. Could metaphors and analogies (from experience) be the missing ingredient of this to succeed? Could using causal models help to overcome these problems? How can we make a model that uses analogies?