Trustworthy ML
Winter Semester 2022-2023
University of Tübingen
Lecturer : Seong Joon Oh
Reminder for video recording
Exercise 1 grades under way
No tutorial after the lecture
But feel free to ask questions.
Attribution to test features
Spatial pooling
Input image
Score map
Class label
CNN
Model
Cat
GAP
Thresholding
FG-BG mask
Zhou et al. Learning deep features for discriminative localization. CVPR’16.
Attribution to test features
Spatial pooling
Input image
Score map
Class label
CNN
Model
Cat
GAP
Thresholding
FG-BG mask
Zhou et al. Learning deep features for discriminative localization. CVPR’16.
What is it?
Attribution to test features
Spatial pooling
Input image
Score map
Class label
CNN
Model
Cat
GAP
Thresholding
FG-BG mask
Zhou et al. Learning deep features for discriminative localization. CVPR’16.
Why is it a cat?
Which features?
For visual models taking image as input:
Single pixel
Image patch
Superpixel
Instance mask
Which features?
For visual models taking image as input:
Cute 90%
Furry 40%
Yellow eyes 50%
Animal 100%
Two ears 100%
Pet 70%
Attributes
Why a cat?
Which features?
For language models taking a token sequence as inputs:
Individual tokens / words are popular candidates for explanation unit.
A Song of (Dis) agreement: Evaluating the Evaluation of Explainable Artificial Intelligence in Natural Language Processing. 2022.
Counterfactual reasoning over features
Input
Is this still predicted as a cat if this feature is missing?
Cat?
Counterfactual reasoning over features
Input
Is this still predicted as a cat if this feature is missing?
What do we mean by “missing” ?
Black pixels? Gray pixels? Pink pixels?
Inpainting based on the context?
Cat?
Counterfactual reasoning over features
Input
Is this still predicted as a cat if this feature is replaced with something else?
Cat?
Counterfactual reasoning over features
Output
Which features contribute to predicting a cat rather than a dog?
Cat? Dog?
Intrinsically interpretable models support this.
For neural networks: expensive computation.
GSWO: A Programming Model for GPU-enabled Parallelization of Sliding Window Operations in Image Processing. 2016
Special case. Feature: pixel. Perturbation: small.
Original pixel value: (232,216,231)
New pixel value: (233,216,231)
Original cat score: 96.5%
New cat score: 96.4%
Special case. Feature: pixel. Perturbation: small.
Original pixel value: (232,216,231)
New pixel value: (233,216,231)
Original cat score: 96.5%
New cat score: 96.4%
Special case. Feature: pixel. Perturbation: small.
Special case. Feature: pixel. Perturbation: small.
SmoothGrad: removing noise by adding noise. 2017.
Issue with input gradients
SmoothGrad: removing noise by adding noise. 2017.
Input
Input grad
Smoothgrad: Smoother input gradients.
SmoothGrad: removing noise by adding noise. 2017.
Input
Smoothgrad
Input grad
Local gradients
x
f(x)
x+δei
f(x+δei)
f
f(x+δei) - f(x) ≈ < δei, df/dx > = δ x df/dxi
Vanilla grad: Measure contribution of pixel i with infinitesimal counterfactual.
Changes in infinitesimally local area
Less local gradients
x+z2
x+z2+δei
Smoothgrad: Measure contribution of pixel i with infinitesimal (δ) counterfactual at multiple points (x+z) around x.
x
f(x+z2)
f(x+z2+δei)
f
x+z1
x+z3
x+z4
Changes in broader
local area
Towards global gradients: Integrated Gradients
x
f(x+α (x’ - x))
f
Integrated gradients
x + α (x’ - x)
x’
Changes in global area
f(x+α (x’ - x)+δei)
Towards global gradients: Integrated Gradients
Formula we derived for contribution of pixel i.
Contribution of pixel i computed by “Integrated Gradients”.
Axiomatic Attribution for Deep Networks. ICML 2017.
Why do we wish to compute “Integrated Gradients” ?
Towards global gradients: Integrated Gradients
Axiomatic Attribution for Deep Networks. ICML 2017.
… and then if we sum over all pixels i, we have
When we define the contribution from pixel i as follows …
Towards global gradients: Integrated Gradients
We note the following: the fundamental theorem of line integrals.
Axiomatic Attribution for Deep Networks. ICML 2017.
Let’s plug below in.
Then, we derive the following property:
Towards global gradients: Integrated Gradients
Completeness Axiom (“necessary condition” for a sound attribution):
Integrated gradients satisfy the “Completeness Axiom”.
Axiomatic Attribution for Deep Networks. ICML 2017.
Towards global gradients: Integrated Gradients
Axiomatic Attribution for Deep Networks. ICML 2017.
Two ways of measuring contribution
x
Local perturbation
Response to local perturbations
x
Response to global perturbations
“Turning off” feature 2
x1
x2
Input gradient
SmoothGrad
Integrated gradients
LIME
SHAP
Zintgraf et al.
Local == Global for sparse linear models.
x
Local perturbation
Response to local perturbations
x
Response to global perturbations
“Turning off” feature 2
x1
x2
Gradient of output wrt feature i is ci .
Effect of “turning off” feature i is ciφi .
Zintgraf et al: Inpaint + Black box computation
Visualizing deep neural network decisions: Prediction difference analysis. ICLR 2017.
Classification score after removing feature i.
And then compute the counterfactual before and after removing feature i.
Approximate this using an inpainting model
Recall: This is expensive.
GSWO: A Programming Model for GPU-enabled Parallelization of Sliding Window Operations in Image Processing. 2016
Zintgraf et al: Inpaint + Black box computation
Visualizing deep neural network decisions: Prediction difference analysis. ICLR 2017.
Zintgraf et al: Inpaint + Black box computation
Left: input grad.
Right: Zintgraf et al.
Pro:
Con:
Visualizing deep neural network decisions: Prediction difference analysis. ICLR 2017.
LIME: Fit a sparse linear model.
"Why should i trust you?" Explaining the predictions of any classifier. KDD 2016.
LIME: Fit a sparse linear model.
Given the general formulation
We specify sparse linear function g by defining:
linearity
sparsity constraint
The function fitting takes place around input x:
Let g follow f (L2 loss) ...
… in the vicinity of x.
"Why should i trust you?" Explaining the predictions of any classifier. KDD 2016.
LIME: Fit a sparse linear model.
"Why should i trust you?" Explaining the predictions of any classifier. KDD 2016.
LIME: Fit a sparse linear model.
Pro: Results are interpretable.
Con: Approximation. Expensive. � Reference is assumed to be a gray image.
"Why should i trust you?" Explaining the predictions of any classifier. KDD 2016.
Shapley values
Assume we have a black box system with binary input vector.
How do you assign the contribution of each feature i ?
System
Input
[0 1 0 0 1 0]
Output
5.27
Shapley values
Binary input features have a clear interpretation of turning on (1) and turning off (0).
The Shapley value determines the individual contribution of each feature. The value is defined as:
Here, the original input x is always treated as [ 1 1 1 1 1 1 ] and an example of a valid sample z is [ 0 1 0 0 1 0 ] for index i=2 (index starts from 1).
Shapley values
The expectation follows:
Shapley values in deterministic form
The expectation follows:
Intuitive description of Shapley values
Average function output with for the inputs
with the feature
Average function output with for the inputs
without the feature
MINUS
Nice property of Shapley values
They satisfy the “Completeness Axiom” as well.
Remember Integrated gradients?
Another nice property of Shapley values
Attribution values φ have the strong monotonicity property if, for every function f and f’ and input x and feature i, the following holds
Implies
That is, if the overall impact of deleting i is greater for f’, then the attribution value for f’ on feature i must be greater than that for f.
Shapley values are special
Theorem:
The only way for the attribution values φ to satisfy both the strong monotonicity and the completeness axiom is to take the Shapley values.
Monotonic Solutions of Cooperative Games.
Defining a “missing feature”.
We needed a good definition of “no information” for the following methods:
What are the typical values taken?
Defining a “missing feature”.
Integrated gradients: Zero (black pixels) as missing features.
Zintgraf et al: Imputation (inpainting) as missing features.
LIME: Mean values (gray pixels) as missing features.
Shapley: Mean values (gray pixels) as missing features.
Problem with fixed missing feature values.
Black and gray pixels also carry information!
Meaningful perturbations
One can also erase information using image blurring.
Interpretable Explanations of Black Boxes by Meaningful Perturbation. ICCV 2017.
Meaningful perturbations
m*: Binary mask that minimally erases information in the image.
||1-m||1 measures the area of the erased area.
fc: Classifier output for class c.
Φ(x0; m): Blurring of image x0 according to the mask m.
Interpretable Explanations of Black Boxes by Meaningful Perturbation. ICCV 2017.
Meaningful perturbations
Score changes after erasing information with blurring.
→ Lets us know when an algorithm may have learned the wrong association.
Interpretable Explanations of Black Boxes by Meaningful Perturbation. ICCV 2017.
Two ways of measuring contribution
Pro
Con
Pro
Con
x
Local perturbation
Response to local perturbations
x
Response to global perturbations
“Turning off” feature 2
x1
x2
Revisiting the choice of features
For visual models taking image as input:
Single pixel
Image patch
Superpixel
Instance mask
Methods using different features
LIME uses superpixels.
What are superpixels?
→ Grouping of pixels respecting colour/edge
similarity. Finer than semantic segmentation
but coarser than raw pixels.
"Why should i trust you?" Explaining the predictions of any classifier. KDD 2016.
We probably care about “interpretable” features.
Interpretability Beyond Feature Attribution: Quantitative Testing with Concept Activation Vectors (TCAV). ICML 2018.
We probably care about “interpretable” features.
Interpretability Beyond Feature Attribution: Quantitative Testing with Concept Activation Vectors (TCAV). ICML 2018.
Testing with Concept Activation Vectors (TCAV)
Interpretability Beyond Feature Attribution: Quantitative Testing with Concept Activation Vectors (TCAV). ICML 2018.
Testing with Concept Activation Vectors (TCAV)
Interpretability Beyond Feature Attribution: Quantitative Testing with Concept Activation Vectors (TCAV). ICML 2018.
Testing with Concept Activation Vectors (TCAV)
Interpretability Beyond Feature Attribution: Quantitative Testing with Concept Activation Vectors (TCAV). ICML 2018.
Testing with Concept Activation Vectors (TCAV)
Interpretability Beyond Feature Attribution: Quantitative Testing with Concept Activation Vectors (TCAV). ICML 2018.
Testing with Concept Activation Vectors (TCAV)
Interpretability Beyond Feature Attribution: Quantitative Testing with Concept Activation Vectors (TCAV). ICML 2018.
Testing with Concept Activation Vectors (TCAV)
Interpretability Beyond Feature Attribution: Quantitative Testing with Concept Activation Vectors (TCAV). ICML 2018.
Testing with Concept Activation Vectors (TCAV)
Interpretability Beyond Feature Attribution: Quantitative Testing with Concept Activation Vectors (TCAV). ICML 2018.
Testing with Concept Activation Vectors (TCAV)
Interpretability Beyond Feature Attribution: Quantitative Testing with Concept Activation Vectors (TCAV). ICML 2018.
Testing with Concept Activation Vectors (TCAV)
Interpretability Beyond Feature Attribution: Quantitative Testing with Concept Activation Vectors (TCAV). ICML 2018.
Explanations linearise models in some way.
Input gradient
Explanations linearise models in some way.
LIME
Explanations linearise models in some way.
Integrated gradients
Explanations linearise models in some way.
SHAP
Explanations linearise models in some way.
Local linear approximation for x, total approximation for f.
f’ (interpretable)
x
f (complicated)
f ≈ f’ only around x
Explanations linearise models in some way.
TCAV: Local linear approximation for g(x), partial approximation for f.
g (complicated)
x
Interpretable features
h (complicated)
h’ (interpretable)
Explanations linearise models in some way.
TCAV = Input gradient over intermediate features
Explanations linearise models in some way.
CAM: Global linear approximation for x, partial approximation for f.
g (complicated)
x
Interpretable features
h (interpretable)
Class activation maps (CAM) for CNNs
Spatial pooling
Input image
Score map
Class label
CNN
Model
Cat
GAP
Thresholding
FG-BG mask
Zhou et al. Learning deep features for discriminative localization. CVPR’16.
Original CAM formulation
Zhou et al. Learning deep features for discriminative localization. CVPR’16.
Training likelihood
Explanation scoremap
Simplifying original CAM formulation
Training likelihood
But note:
Define:
Then, we may rewrite:
Simplifying original CAM formulation
That is, you don’t need to do matrix multiplication to generate the score map!
Just take the last-layer feature map with channel index = class of interest.
Simpler training formulation:
We also simplify explanation algorithm
Simplifying original CAM formulation
But you do need to modify the original model a bit.
Useful technique: Turning a FC layer into 1x1 Conv layer.
FC operation is identical to 1x1 Conv operation, except that
GAP → FC
1x1 Conv → GAP
Code becomes much simpler!
Original CAM formulation
Modified CAM formulation