Responsible AI by Design

Module 4 – Transparency and Explainability

Frank Rudzicz

2025-08-29

What you’ll learn today

  • When and why to use explanations in AI systems
  • The difference between faithful vs plausible explanations
  • What recent research says about LLM self-explanations, SHAP, integrated gradients, and counterfactuals
  • How to avoid misuse and design actionable, robust explanations for business contexts
  • How to critically evaluate explanation outputs presented to you

Note

🤔Framing: Explanations are a safety and accountability tool—not a magic truth serum for LLMS, nor a compliance checkbox.

Definitions

  • The following terms are often tossed around as if they’re synonymous. Let’s try to stick to these definitions:
    • Explainability: Describes how the model works and what it ‘knows’. This is usually expressed in intrinsic terms of the model itself.
      • E.g., “This model represents the notion of ownership primarily (82%) through layers 5-8
    • Interpretability: Describes why a model made a particular decision. This is usually expressed in extrinsic terms of the data sample.
      • E.g., “This data point was classified as `reject’ because the credit score was < 660 and the annual income was < $35K
    • Transparency: Describes the ‘openness’ of the entire process, including explicitly sharing details such as 1) training data, 2) source code, 3) training regimen, …
      • E.g., “This model was trained on the MIMIC dataset using code here

A rose by any other name…

There are alternative taxonomies.

  • Global: Understanding overall model behaviour
  • Local: Understanding individual predictions

Note

  • Both are essential in responsible AI workflows

Why explainability matters

  • Regulators increasingly demand it
  • Customers increasingly expect clarity and fairness
  • Organizations need it to maintain trust
  • Internal teams need it for debugging and risk management

📚 (Doshi-Velez and Kim 2017; Lipton 2018; Barredo Arrieta et al. 2020)

Explanations ≠ Truth

But men may construe things after their fashion, / Clean from the purpose of the things themselves” (I. iii. 34–35).
— Cicero (via William Shakespeare)

Explanations ≠ Truth

  • Prediction answers: What output did the model give?
  • Explanation answers: What appeared* to drive this output—under specific tests and assumptions?*

Warning

Be aware of post-hoc reasoning. Was the interpretation for a decision extracted during the decision itself, or did an LLM explain its own decision after the fact?

Properties of Good Explanations

  • Faithfulness: Matches the model’s true logic/behaviour
  • Plausibility: Intuitively satisfying to a human
  • Contextual: Tailored to user knowledge level
  • Contrastive: “Why A, not B?
  • Actionable: Can guide decisions or fixes

Warning

Misuse risk: Plausible stories can mislead if they aren’t faithful. Don’t mistake rationalizations for reasons. Beware confirmation bias.

Activity 4.1: Everyday explanations

What kinds of explanations do you encounter day-to-day? Are they satisfying?

  • 🤔 Think — 60s
  • ✍️ Jot 2 examples you’ve seen this week (e.g., credit score reason, recommendation “because you watched…”, smartwatch notification).
  • For each, rate 1–5 on:
    • Clarity (can a layperson follow it?)
    • Fairness (does it justify treatment?)
    • Actionability (does it tell you what to do next?)
    • Rubric: 1 = poor / none ; 3 = mixed ; 5 = excellent

What Is a Black-Box Model?

  • A model whose internal logic is opaque, even to its developers
    • e.g., deep neural networks, ensemble models like XGBoost
  • Can be highly accurate but difficult to explain
    • We know what goes in, we know what comes out — but not what happens in between

Note

A model can be ‘black-box’ even if it is under your desk on your own Linux machine. It’s about inscrutability, not transparency.

Of course, the problem is exacerbated if you can only access the model remotely through API calls.

Interpretable Models

  • Models whose decision-making logic is available. E.g.,
    • Linear regression
    • Decision trees
    • Rule-based systems

Note

  • Easier to audit and explain
  • Often used in high-stakes domains (e.g. healthcare, finance)

Trade-offs

Factor Black-box Models Interpretable Models
Accuracy Often higher Sometimes lower
Transparency Low High
Trust Requires justification Built-in
Flexibility High Often limited

These are not universally-acknowledged truths.

🤔 Where in your industry would you accept a small performance hit in exchange for clarity?

Choosing the Right Model

  • ⬆️ When stakes are high: prefer explainability
  • ⬇️ When stakes are low: go for performance
  • Regulatory guidance increasingly favours interpretable or explainable models

Types of Explanations

  • Feature importance: What features matter most?
  • Counterfactuals: What would have changed the decision?
  • Partial dependence: How does one feature affect the output?

Visual Explanations

Heatmaps

(for images)

From here

Visual Explanations

Text attention overlays

From Feng, Shaib, and Rudzicz (2020)

Visual Explanations

Feature contribution charts

Useful when using ‘structured’ data

From here

Case study: pneumonia risk

  • Caruana et al. (2015) studied 14,199 pneumonia patients
    • ICD-9-CM principal diagnosis of pneumonia at admission
    • 10.86% died. Bagging is used to ‘avoid overfitting’.
    • A single (😳) 70:30 train:test split was used…
  • 46 features, \(\color{green}{f_j}\), extracted, e.g.,
    • Patient history: chronic lung disease (+/-), admitted to ER (+/-), age (ℤ?)
    • Physical exam: heart rate (ℝ?), diastolic blood pressure (ℝ?)
    • Lab findings: potassium level (ℝ?), sodium level (ℝ?)
    • X-rays: pleural effusion, positive chest x-ray

Generalized additive models (GAMs)

  • Given a data set with \(N\) instances, \(\mathcal{D}=\{(x_i, y_i)_1^N\}\), a standard GAM has the form

\(g(E[y])=\beta_0 + \sum_j \color{green}{f_j}(x_j)\)

  • where \(g(\cdot)\) is the link function, and “for each term \(\color{green}{f_j}\), \(E[\color{green}{f_j}]=0\)”.
    • Logistic regression is a special form of GAM where each \(\color{green}{𝑓_𝑗}\) is linear.
  • To improve accuracy, pairwise interactions can be added:

\(g(E[y])=\beta_0 + \sum_j \color{green}{f_j}(x_j) + \sum_{i\neq j} \color{red}{f_{i,j}}(x_i, x_j)\)

Case study: pneumonia risk

  • Sort features by ‘importance’
    • Sec 5.3: ask an expert to rank them for you, or rank by “drop in AUC when the term is removed
    • Better way (?): filter method, i.e., statistical tests of significance.
  • Plot those features in terms of their ability to predict the outcome.
    • Green bars are ±1 standard deviation of the variation in the risk score (\(y\)-axis) measured by 100 rounds of bagging.

Case study: pneumonia risk

Tip

OK, good. Risk of pneumonia increases with age.

Important

Uh oh, bad. Risk of pneumonia decreases if you have asthma??

Note

  • It turns out, in the data, patients with a history of asthma who presented with pneumonia usually were admitted not only to the hospital but directly to the ICU.
  • Author’s solution: remove the term, or ask a human to redraw the graph.
    • This assumes the channel effect (or bias) is even recognized in the first place.

What is LIME?

  • Local Interpretable Model-agnostic Explanations (LIME) explains a single prediction by fitting a simple, human-readable model around that instance.
  • Core idea: sample perturbed neighbours of \(x_0\), weight them by proximity, and fit a sparse linear surrogate whose coefficients are shown as the “explanation.”
  • Works across tabular, text, and image models via an interpretable representation (e.g., words present/absent, image superpixels on/off).
  • Useful for debugging, spot-checking models, and building trust (with caveats)

📚 (Ribeiro, Singh, and Guestrin 2016)

How LIME Works (Step-by-Step)

For an instance \(x_0\), LIME solves

\(\arg\min_{g \in \mathcal{G}} \underbrace{\mathcal{L}\!\big(f, g, \pi_{x_0}\big)}_{\text{local fidelity}} \;+\; \underbrace{\Omega(g)}_{\text{simplicity}}\)

  1. Generate perturbed samples \(z\) near \(x_0\)
  2. Weight samples with a locality kernel \(\pi_{x_0}\)(z)
  3. Fit a sparse linear model \(g\)
  4. Explain via the top \(k\) coefficients of \(g\)

From Ribeiro, Singh, and Guestrin (2016).

LIME for text, tables, images

📊 Demo: LIME playground

Strengths and weaknesses of LIME

  • Model-agnostic: works with any classifier/regressor
  • Human-legible: lists of features, coloured pixels
  • Fast for interactive use
  • Bridges teams: data scientists ⇔ product ⇔ compliance
  • Instability: Results change with parameters, sampling, randomness.
    • This can hide important features or find spurious ones (Garreau 2020)
  • Adversarially foolable: a model can be scaffolded to keep biased predictions while making LIME (and SHAP) look innocuous.
  • Local \(\neq\) causal: coeffients of local fit are not interventions, and correlation is not causation
  • Act local, think local: the neighbourhood you sample defines the story you see.

Recent developments

LIME Best-practice checklist

  1. Quantify fidelity: report surrogate \(R^2\) / loss on the weighted neighbourhood.
  2. Stability checks: rerun with different seeds; vary kernel width; report variance of top-\(k\)
  3. Neighbourhood sanity: visualize distance histogram of sampled points; ensure they’re actually near \(x_0\).
  4. Feature dependence: test with/without correlated features; confirm the story doesn’t flip.
  5. Don’t treat as causal: pair with counterfactual tests or anchors (here) for decision support.
  6. Model comparison: use SP-LIME to compare candidates by feature-coverage, not by one screenshot.

(Ribeiro, Singh, and Guestrin 2016; Garreau 2020)

Four easy pieces

  1. LLM self-explanations aren’t reliably faithful
    • treat rationales as UI, not audit evidence.
  2. SHAP can mislead on feature importance under common conditions
    • require sanity/stability tests.
  3. Counterfactuals must be robust/actionable
    • prefer ranges + recertification and feasibility checks.
  4. Human studies favour region-based recourse
    • design explanations people can actually use.

1. LLM self-explanations

LLMs can produce explanations along with their response, called self-explanations. (S. Huang et al. 2023)

For example, when analyzing the sentiment of a movie review, the model may output not only the positivity of the sentiment, but also an explanation (e.g., by listing the sentiment-laden words such as “fantastic” and “memorable” in the review). How good are these automatically generated self-explanations?

1. LLM self-explanations

Self-explanations cannot be assumed to be faithful without structured validation. (Madsen, Chandar, and Reddy 2024)

  • LLMs can produce convincing self-explanations (e.g., chain-of-thought)
  • Faithfulness varies by task, model, and explanation type
  • Risk: humans tend to over-trust fluent rationales
  • Solution?: Get the predicting model to produce counterfactuals, and then run those counterfactuals.

1. LLM implications for leaders

  • Don’t use self-explanations as audit evidence
  • Treat rationales as UI features, not as truth
  • Always run self-consistency checks: mask or edit the named feature → does the outcome change?

2. SHAP - Overview

  • SHapley Additive exPlanations
  • Uses game theory to assign each feature a contribution score
  • Often described as fair, consistent, and model-agnostic
  • Works across model families via different explainers
  • 📚 (Lundberg and Lee 2017) ; 🛠️ code

Note

Key idea: Share the prediction among features according to their marginal contributions over many coalitions.

2. How SHAP Works

For an instance \(x_0\), each feature \(i\) receives a Shapley value \(\phi_i\) summarizing its average marginal contribution across feature coalitions: \[ \phi_i = \sum_{S \subseteq F \setminus \{i\}} \frac{|S|!\,(|F|-|S|-1)!}{|F|!}\; \Big(f_{S \cup \{i\}} - f_S\Big) \]

  • In practice, SHAP implements this with model-specific or model-agnostic approximations.

2. The SHAP Toolkit (Explainers)

  • TreeExplainer (trees/ensembles; fast, exact/approx)
  • KernelExplainer (model-agnostic; local weighted regression around \(x_0\))
  • DeepExplainer / GradientExplainer (neural nets; gradient/DeepLIFT-style)
  • LinearExplainer (linear models with correlated features)

Keep in mind: Explainer choice affects speed, variance, and assumptions.

2. SHAP in Action (Global & Local)

  • Global: beeswarm plots (distribution of \(\phi_i\) across many points); dependence plots (feature value vs SHAP value)
  • Local: horizontal bar chart for a single prediction (top-\(k\) features)

2. Examples: movies and meerkats

2. What SHAP Is (and Isn’t)

Is:

  • A principled feature attribution method; helpful for debugging and communicating local/global patterns.

Isn’t:

  • Causal by default. A large \(\phi_i\) does not imply that intervening on feature \(i\) will change the outcome in the real world.

Warning

Caveat: Correlated features, leakage, or irrelevant features can distort SHAP importance. Recent work (e.g., X. Huang and Marques-Silva (2024)) shows SHAP can assign zero to relevant features and high weight to irrelevant ones.

2. Known Failure Modes

  • Correlation & interactions: attributions can shift among correlated features.
  • Off-manifold perturbations (KernelExplainer): unrealistic samples → spurious stories.
  • Parameter sensitivity: kernel width, background data, and random seeds move explanations.
  • Adversarial camouflage: models can be trained to look benign under SHAP while retaining harmful logic.

Keep Your Guard Up!

2. SHAP — Misuse Scenarios (Don’t Do This)

  • Treating SHAP bars as causal levers
  • Presenting SHAP plots as regulatory compliance without sanity/stability checks
  • Over-interpreting attractive visuals without robustness testing

2. SHAP — Good Practice Checklist

  1. Background data matters: choose a representative background; state how you chose it.
  2. Stability checks: vary kernel width/seed/background; show variance in top-(k) features.
  3. Sanity checks: randomize labels/features → explanations should collapse to noise.
  4. Correlation checks: test subsets / condition on key covariates; compare with counterfactual probes.
  5. Pair with recourse: don’t present bars alone; accompany with validated, range-based recourse.
  6. Document assumptions: explainer, version, data slice, valid-until.

2.5 Integrated Gradients (IG)

  • SHAP is model-agnostic and game-theoretic; great for trees & tabular data.
  • For deep neural networks, gradient-based methods can be more direct and efficient on the model’s native representation.
  • Integrated Gradients (IG) attributes by integrating the gradient along a path from a baseline \(x'\)to the input \(x\).
  • IG brings different assumptions & pitfalls (e.g., baseline choice); a useful contrast with SHAP.

2.5 Integrated Gradients

Definition Sundararajan, Taly, and Yan (2017): \[ IG_i(x) \;=\; (x_i - x'_i)\, \int_{0}^{1} \frac{\partial f\!\left(x' + \alpha(x - x')\right)}{\partial x_i}\, d\alpha \]

  • Pros: faithful to gradients, efficient, no coalitions.
  • Cons: baseline-dependent; can be sensitive to path choice & saturation.
  • Use when: deep nets on text/images/tabular embeddings; pair with the same stability/sanity habits you apply to SHAP.

Comparison: SHAP vs IGs

  • SHAP: game-theoretic, model-agnostic, but unstable with correlations
  • IG: gradient-based, deep-learning oriented, baseline-dependent
  • Both risk misleading attributions if applied without care

Note

Takeaway: Choose method based on context, validate with sanity checks, and never confuse attribution with causality.

3. Counterfactuals

  • “What-if” explanations: how input must change to alter outcome
  • Example: “If income were $55k instead of $49k, the loan would be approved.”
    • One can’t just increase one’s salary, can one?
  • 💪 Strengths:
    • Intuitive for humans
    • Actionable when designed properly
    • Useful for individual recourse

3. Problems with counterfactuals

  • Single-point edits are fragile to model changes
  • May recommend unethical or immutable changes (e.g., gender, race)
  • Lack robustness across retrains

3. Robust counterfactuals

  • Problem: A counterfactual \(x'\) flips the prediction for \(x\) now, but should also remain valid under model updates, input noise, and distribution shift.
  • Model-set view: Let \(\mathcal{M}\) be a set of plausible future/retrained models. Robust validity can be required as:
    • Hard (for all models): \[ \forall\, M \in \mathcal{M}:\; f_M(x') = y^\star \]
    • Probabilistic (likely across models): \[ \Pr_{M \sim \mathcal{M}}\!\big[f_M(x') = y^\star\big] \;\ge\; \tau \]
  • Why standard counterfactuals fail: optimized for a single snapshot (M_t); sensitive to correlated features, local boundary shifts, and off-manifold proposals.

3. Robust counterfactuals

Jiang et al. (2024) formalizes robustness, failure modes, and evaluation.

  • Evaluation metrics (common in robust-CE studies):
    • Proximity of \(x'\) to \(x\): \(\ell_1\), \(\ell_2\)
    • Plausibility: outlier scores (e.g., Local Outlier Factor), data-manifold checks
    • Robust validity: fraction of retrained models \(M \in \mathcal{M}\) where \(f_M(x') = y^\star\)
  • Method families highlighted by Jiang et al.:
    • Provable robustness via interval abstractions (verify \(\Delta\)-robustness; MILP-based checks) and construct CEs guaranteed to remain valid within certified perturbation sets.
    • Ensemble / model-set optimization: choose \(x'\) that maximizes worst-case or expected validity across \(M \in \mathcal{M}\).
    • Regularized objectives: multi-objective trade-off between proximity, sparsity, plausibility, and robustness.

3→4. Robust counterfactuals

4. Human-Centered Studies

VanNostrand et al. (2024) ran a between-subjects user study (\(N = 252\)) to examine the effects of counterfactual explanation types .

  • Region-based counterfactuals improve user understanding and confidence
  • Visual vs text formats affect speed and confidence, but not comprehension
  • Simple interfaces reduce cognitive load

Qualitative themes (why users liked regions):

  • Ranges give room to maneuver and feel more realistic; make trade-offs explicit.
  • Users asked for justification: “Why these ranges?” → desire for provenance/version & evidence that the ranges are reliable.

Note

Why this matters: This isolates what (point vs region) from how (numeric vs text vs visual), so we can teach design choices with evidence—not “vibes”.

Deployment playbook

  • Explanations are tools, not truths
  • Favour interpretable models; otherwise add tests, ranges, and stamps
  • Avoid misuse: treat explanations as communication aids, not ultimate evidence
  • Focus on actionability and human comprehension

Steps before shipping

  1. Prefer interpretable models for high-stakes use
  2. Define audience and explanation goals (debugging, assurance, compliance)
  3. Run the test battery: stability, self-consistency, sanity checks, counterfactual robustness, actionability, human comprehension

Red flags & do-instead

  • ❌ Free-form LLM rationales as audit evidence
    • → ✅ Structured tests and logs
  • ❌ SHAP bars as causal
    • → ✅ Validate with causal/abductive checks
  • ❌ Single-point counterfactuals
    • → ✅ Range-based recourse with feasibility constraints
  • ❌ No disclaimers
    • → ✅ Version stamps and validity windows

Case vignette: Credit approval

  • Bad recourse: “Increase income to $55k”
    • (unrealistic, single point)
  • Good recourse: Income range $54–58k + DTI < 35%
    • (feasible, validated, time-bound)

Version-stamped: Model v1.9, trained to 2025-06, valid until 2025-09

Caveats in Explainability

  • False sense of understanding
  • Explanations ≠ justification
  • Can be manipulated or cherry-picked
  • The “Rashomon Effect”
    • Many explanations may seem plausible
    • Which one is “right”?

Activity 4.2: Transparency audit

Choose a real or hypothetical AI decision-making system and answer:

  1. Who are the stakeholders?
  2. Is the system explainable?
  3. What tools or strategies are used (or should be used)?
  4. What risks arise from opacity?
  • ✍️ Write a short report (800–1024 words)
    • I’m looking for clarity, appropriate use of concepts (e.g., LIME, SHAP), and thoughtfulness about limitations and ethics
    • Ideally, use cited literature, including the system itself

Looking Ahead

Next module: Accountability & Governance

References

Barredo Arrieta, Alejandro, Natalia Díaz-Rodríguez, Javier Del Ser, Adrien Bennetot, Siham Tabik, Alberto Barbado, Salvador Garcia, et al. 2020. “Explainable Artificial Intelligence (XAI): Concepts, Taxonomies, Opportunities and Challenges Toward Responsible AI.” Information Fusion 58 (June): 82–115. https://doi.org/10.1016/j.inffus.2019.12.012.
Caruana, Rich, Yin Lou, Johannes Gehrke, Paul Koch, Marc Strum, and Noémie Elhadad. 2015. “Intelligible Models for HealthCare.” In Proceedings of KDD, 1721–30. https://doi.org/10.1145/2783258.2788613.
Doshi-Velez, Finale, and Been Kim. 2017. “Towards A Rigorous Science of Interpretable Machine Learning.” arXiv. https://doi.org/10.48550/arXiv.1702.08608.
Feng, Jinyue, Chantal Shaib, and Frank Rudzicz. 2020. “Explainable Clinical Decision Support from Text.” In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP), 1478–89. Online: Association for Computational Linguistics. https://doi.org/10.18653/v1/2020.emnlp-main.115.
Garreau, Damien. 2020. “Explaining the Explainer: A First Theoretical Analysis of LIME.” In Proceedings of the 23rdInternational Conference on Artificial Intelligence and Statistics (AISTATS).
Huang, Shiyuan, Siddarth Mamidanna, Shreedhar Jangam, Yilun Zhou, and Leilani H. Gilpin. 2023. “Can Large Language Models Explain Themselves? A Study of LLM-Generated Self-Explanations.” arXiv. https://doi.org/10.48550/arXiv.2310.11207.
Huang, Xuanxiang, and Joao Marques-Silva. 2024. “On the Failings of Shapley Values for Explainability.” International Journal of Approximate Reasoning 171: 109112. https://doi.org/https://doi.org/10.1016/j.ijar.2023.109112.
Jiang, Junqi, Francesco Leofante, Antonio Rago, and Francesca Toni. 2024. “Robust Counterfactual Explanations in Machine Learning: A Survey.” In Proceedings of the Thirty-ThirdInternational Joint Conference on Artificial Intelligence, 8086–94. Jeju, South Korea: International Joint Conferences on Artificial Intelligence Organization. https://doi.org/10.24963/ijcai.2024/894.
Lipton, Zachary C. 2018. “The Mythos of Model Intepretability.” Queue 16 (3). https://doi.org/10.1145/3236386.
Lundberg, Scott, and Su-In Lee. 2017. “A Unified Approach to Interpreting Model Predictions.” arXiv. https://doi.org/10.48550/arXiv.1705.07874.
Madsen, Andreas, Sarath Chandar, and Siva Reddy. 2024. “Are Self-Explanations from Large Language Models Faithful?” arXiv. https://doi.org/10.48550/arXiv.2401.07927.
Ribeiro, Marco Tulio, Sameer Singh, and Carlos Guestrin. 2016. “"Why Should I Trust You?": Explaining the Predictions of Any Classifier.” In Knowledge Discovery and Data Mining (KDD). https://doi.org/10.1145/1235.
Saadatfar, Hamid, Zeinab Kiani-Zadegan, and Benyamin Ghahremani-Nezhad. 2024. “US-LIME: Increasing Fidelity in LIME Using Uncertainty Sampling on Tabular Data.” Neurocomputing 597: 127969. https://doi.org/https://doi.org/10.1016/j.neucom.2024.127969.
Slack, Dylan, Sophie Hilgard, Emily Jia, Sameer Singh, and Himabindu Lakkaraju. 2020. “Fooling LIME and SHAP: Adversarial Attacks on Post Hoc Explanation Methods.” In Proceedings of the AAAI/ACM Conference on AI, Ethics, and Society, 180–86. New York NY USA: ACM. https://doi.org/10.1145/3375627.3375830.
Sundararajan, Mukund, Ankur Taly, and Qiqi Yan. 2017. “Axiomatic Attribution for Deep Networks.” In Proceedings of the 34 Th International Conference on Machine Learning. Sydney, Australia.
Tan, Zeren, Yang Tian, and Jian Li. 2023. GLIME: General, Stable and Local LIME Explanation.” In 37th Conference on Neural Information Processing Systems.
VanNostrand, Peter M., Dennis M. Hofmann, Lei Ma, and Elke A. Rundensteiner. 2024. “Actionable Recourse for Automated Decisions: Examining the Effects of Counterfactual Explanation Type and Presentation on Lay User Understanding.” In Proceedings of the 2024 ACM Conference on Fairness, Accountability, and Transparency, 1682–1700. FAccT ’24. New York, NY, USA: Association for Computing Machinery. https://doi.org/10.1145/3630106.3658997.