cs3244 11a.explainable-Ai
cs3244 11a.explainable-Ai
AI (XAI)
CS 3244 A
Machine Learning
Recap from W10a&b
Case 1:
Does patient have cancer? Why??
LIME
How to describe with just 𝑥1 and 𝑥2 ?
Non-Linear Decision Boundary 𝑓 𝒙
𝑥2 Prediction Model
𝑓 𝒙
𝑥1
• Non-linear model of 𝒙 = 𝑥2
FN ⋮
FN FN • Shown as curvy decision boundary
Explanation: Gradients
𝑑𝑓 𝜕𝑓/𝜕𝑥1
𝑔 𝒙 = ∇𝑓 𝒙 = = 𝜕𝑓/𝜕𝑥2
𝑑𝒙
⋮
• Steepness for each feature 𝑥𝑟
• Difficult to remember, since gradients
𝑥1 are different for each instance (point)
Image Credit: https://santiagof.medium.com/model-interpretability-making-your-
model-confess-lime-89db7f70a72b NUS CS3244: Machine Learning 23
LIME
Local Interpretable Model-agnostic Explanations
𝑥2 Prediction Model
𝑓 𝒙
𝑥1
• Non-linear model of 𝒙 = 𝑥2
⋮
• Shown as curvy decision boundary
Explanation: LIME
1. Starting with instance 𝒙 to explain
2. Focus on Local region
3. Training set as neighbors 𝒙 𝜂 ∈ 𝑋 𝜂
4. Train surrogate model, e.g., linear:
𝑛
𝑥1 𝑔 𝒙 =𝒘⋅𝒙= 𝑤𝑟 𝑥𝑟
𝑟=0
Image Credit: https://santiagof.medium.com/model-interpretability-making-your-
model-confess-lime-89db7f70a72b NUS CS3244: Machine Learning 24
Python API:
LIME https://github.com/marcotcr/lime
Find “best” explainer 𝑔 that minimizes 𝜉 𝒙
“Faithful” “Simple”
argmin 𝜉 𝒙 = 𝐿 𝑓, 𝑔, 𝜋𝑥 + Ω 𝑔
𝑔∈𝐺
Case 1: Does patient have cancer? Why do the two set of weights differ?
Grad-CAM
Explaining Image Predictions
• LIME to explain image prediction?
• What are the input features?
• Feature = Pixels?
• Too many features
• Need “super pixels”
𝑨 𝐿−1 𝑨𝐿
𝑐
Backprop
Forward prop through Conv layers ∇𝑦ො 𝑐 𝑨[𝐿−1]
Key concepts
Learn Spatial Feature Flattening Learn Nonlinear Features Classification
• Series of multiple convolution + • Convert to • With fully connected layers • Softmax ≔ Multiclass
pooling layers fixed-length (regular neurons) Logistic Regression
• Progressively learn more diverse 1D vector • Learns nonlinear relations • Feature input = image
and higher-level features with multiple layers embedding vector
(typically large vector)
Image credit: https://towardsdatascience.com/a-comprehensive-
guide-to-convolutional-neural-networks-the-eli5-way-3bd2b1164a53 NUS CS3244: Machine Learning 30
Grad-CAM Example: Why did the CNN predict “9”?
𝑘 = 17
× 0.5
𝑦ො = "9"
𝑘 = 22
× 0.4 +
𝒙
𝑘 = 31 ReLU 𝛼𝑘 𝑨𝑘
𝑐 [𝐿−1]
× 0.1 𝑘
Class Activation Map
(CAM)
𝐿−1 𝑐
𝑨 𝐿−1 𝑨𝑘 × 𝛼𝑘 𝑐 = "9"
Final Conv Layer 𝐿 − 1 Activation Importance Explain saliency
Activation Maps Map Weight for “9”
NUS CS3244: Machine Learning 31
Grad-CAM Example: What is the evidence to predict “7”?
𝑘 = 17
× 0.1
𝑦ො = "9"
𝑘 = 22
× 0.4 +
𝒙
𝑘 = 31 ReLU 𝛼𝑘 𝑨𝑘
𝑐 [𝐿−1]
× 0.1 𝑘
Class Activation Map
(CAM)
𝐿−1 𝑐
𝑨 𝐿−1 𝑨𝑘 × 𝛼𝑘 𝑐 = "7"
Final Conv Layer 𝐿 − 1 Activation Importance Explain saliency
Activation Maps Map Weight for “7”
NUS CS3244: Machine Learning 32
𝑐
Importance Weight 𝛼𝑘 of Activation Map
𝑐 𝑐
𝜕 𝑦Ƹ 𝜕 𝑦Ƹ
[𝐿−1] [𝐿−1] 𝐿−1 𝐿−1
𝑎11𝑘 ⋯ 𝑎1𝑤𝑘 𝑐 𝜕𝑎11𝑘 ⋯ 𝜕𝑎1𝑤𝑘
[𝐿−1] 𝜕 𝑦ො
𝑨𝑘 = ⋮ ⋱ ⋮ = ⋮ ⋱ ⋮
[𝐿−1]
[𝐿−1]
𝑎ℎ1𝑘 ⋯ 𝑎 [𝐿−1] 𝜕𝑨𝑘 𝜕 𝑦Ƹ 𝑐 ⋯ 𝜕 𝑦Ƹ 𝑐
ℎ𝑤𝑘 [𝐿−1]
≠ 𝑾𝑘 𝜕𝑎ℎ1𝑘
𝐿−1 𝐿−1
𝜕𝑎ℎ𝑤𝑘
Activation of
𝜕𝑓 𝐿−1 𝑑𝑔 𝐿−1 𝜕𝑓 𝐿 𝑑𝝈 𝑑𝑦ො 𝑐
𝑘th channel
[𝐿−1] 𝑑𝑓 𝐿−1 𝜕𝑔 𝐿−1 𝑑𝑓 𝐿 𝑑𝝈
=
at pixel (ℎ, 𝑤) 𝜕𝑎 ℎ𝑤𝑘
in layer 𝐿 − 1
𝑨 𝐿−1 𝑨𝐿
𝑐
Backprop
Forward prop through Conv layers ∇𝑦ො 𝑐 𝑨[𝐿−1]
Key concepts
Learn Spatial Feature Flattening Learn Nonlinear Features Classification
• Series of multiple convolution + • Convert to • With fully connected layers • Softmax ≔ Multiclass
pooling layers fixed-length (regular neurons) Logistic Regression
• Progressively learn more diverse 1D vector • Learns nonlinear relations • Feature input = image
and higher-level features with multiple layers embedding vector
(typically large vector)
Image credit: https://towardsdatascience.com/a-comprehensive-
guide-to-convolutional-neural-networks-the-eli5-way-3bd2b1164a53 NUS CS3244: Machine Learning 34
Grad-CAM Steps Python API:
https://github.com/jacobgil/pytorch-grad-cam
d
• Visualizations 3 Physical activity is good for health. 55% Rubric-Informed
Hu
…
Human-
Let’s walk more and reduce sitting XAI Judge (IRIS)
an-informe
How People actually Reason (with Errors) How XAI Support Reasoning and Mitigate Errors time.
• Dual process model • Mitigate representative bias
Philosophy
How People Psychology
actually
Reason How
• Mitigate XAI Supports
availability bias Reasoning Related to dreamlining +1% Non-accountable
man-inspired
• System 1 Heuristic Biases
• Mitigate anchoring bias
(with
• System 2 Weaknesses Errors) (and Mitigates Errors) Is a musical time +2% AI Judge
• Mitigate confirmation bias Has prerequisite playing game +1%
• Moderate trust
XAI
“My best friend will be
going to school in another
country for 4 years.”
m
“My best friend is leaving “best, friend, going, school,
the country for a long time country, years, current,
Hu
to study overseas. So sad!” advance, cold, sad”
Text-to-Image
a b c
Generative AI
Hu d
ma nd e
n-confou
Parsimony vs. Performance [CHI’20] Privacy harms Explanations [CHI’22] Explanations harm Privacy [ICCV’21] XAI Perceptual Process [CHI’22]
Classification: Cycling
Blur Level None Weak Strong
Linear Cognitive-GAM GAM
Image
Unbiased Biased
Regular
Saliency Map
Stimuli 1 Select 2 Organize 3 Interpret
Debiased-CAM
to mitigate image perturbations with
faithful visual explanations of machine learning
CNN0 “Fish”
Biased-CAM0
Bias
for “Fish”
CNN0 “Dog”
45
Fine-tuned Model Unbiased-CAM
CNN0 “Fish”
Biased-CAM0
Bias
CNNf “Fish”
46
Debiased Model Unbiased-CAM
CNN0 “Fish”
Biased-CAM
Bias
Secondary
prediction task
Multi-task (mt)
prediction
Primary
CNNdf “Fish” Prediction task
47
Debiased Model Unbiased-CAM
CNNdf “Fish”
48
ForImageForbias
different leadsprediction
different totasks
prediction CAMand distortions
tasks
bias…types …
Blur (𝜎) Blur (𝜎) Color Temperature (Δ𝑇) Day-Night Ratio (𝜌)
Bias Level 0 16 32 0 16 32 0K –1600K –3600K 0 0.4 0.8
Saliency
Regular
CNN
0
FineTuned
CNN
Debiased
CNN
Prediction Explanation
Performance Faithfulness
Precision-Recall AUC Pearson Correlation Coefficient
DebiasedCNN
FineTunedCNN
RegularCNN
0.90
0.85
0.70
-5400 (6600) 5400
Color Temperature Bias Night Bias Ratio (𝜌)
sb = single-bias
RegularCNN DebiasedCNN (sb) FineTunedCNN (sb) DebiasedCNN (mb) FineTunedCNN (mb)
mb = multi-bias
Debiased-CAM helps
Wrapping Up
[W10b] Student Learning Outcomes
Saliency Map
Blackbox
Grad-CAM explanation 𝑔
CNN model 𝑓