Interpretability & Explainability
Level: 5 (Mastery — cross-domain: math + coding + proof/derivation) Time limit: 90 minutes Total marks: 60
Instructions: Answer all three questions. Show full derivations. Where code is requested, pseudocode or runnable NumPy/PyTorch is acceptable. Justify every modelling assumption.
Question 1 — Shapley Values: Axioms, Kernel, and Superposition (22 marks)
The SHAP framework attributes a prediction to features via Shapley values from cooperative game theory. For a value function with , the Shapley value of feature is
(a) Prove the efficiency (local accuracy) axiom: . Structure your proof around counting, over all orderings, the marginal contributions. (6)
(b) Consider a purely linear model with value function under feature independence. Derive a closed form for and interpret why SHAP reduces to the "input times weight-deviation" attribution here. (5)
(c) Superposition tension. Suppose an interpretability tool assumes each of latent neurons encodes exactly one human concept, but the network actually stores concepts in superposition as near-orthogonal directions with small for . Using the Johnson–Lindenstrauss lemma, state (with the standard bound) the minimum dimension needed to embed vectors with pairwise distances preserved to distortion . Then argue quantitatively why single-neuron Shapley attribution can be misleading under superposition. (6)
(d) LIME fits a local surrogate by minimising . Give one concrete failure mode where LIME and SHAP disagree on feature ranking, and identify which SHAP axiom LIME may violate. (5)
Question 2 — Grad-CAM Derivation and a Saliency Sanity Check (20 marks)
(a) For a CNN with final conv feature maps (channel ) and class score (pre-softmax logit), derive the Grad-CAM localization map
Explain the role of , the global-average-pooling of gradients, and the final . (8)
(b) Prove that for a network whose head is a single linear layer on top of the conv maps (i.e. GAP then linear), Grad-CAM's weights satisfy up to the pooling constant — i.e. Grad-CAM reduces to CAM. Show the gradient computation explicitly. (6)
(c) Sanity-check coding task. Adebayo et al. showed some saliency methods fail a model-parameter randomization test. Write pseudocode for this test and state the pass/fail criterion. Explain, in probabilistic terms, why a method that passes gives more trustworthy explanations. (6)
Question 3 — Activation Patching, Probing, and Counterfactuals (18 marks)
(a) Activation patching (causal tracing). Define clean run with output logit and corrupted run with . Give the formal definition of the patching effect at layer , position (denominator-normalised), and explain why this is an interventional/causal metric rather than a correlational one. (6)
(b) Probing pitfall (theory). A linear probe achieves accuracy predicting concept from representation . Prove that high probe accuracy does not imply the model uses concept : construct a minimal counterexample where is linearly decodable from yet has zero causal effect on the output. Relate this to why activation patching is the stronger test. (6)
(c) Counterfactual explanation optimisation. A counterfactual for input w.r.t. classifier and target class minimises
Take and a logistic model . Derive the gradient , and explain why the term produces sparse counterfactuals (few features changed). (6)
Answer keyMark scheme & solutions
Question 1
(a) Efficiency proof — 6 marks
Write the Shapley value in ordering form. Let be the set of all permutations of . For , let be the set of players preceding . Then
(2 marks — equivalence of weight to counting orderings where the predecessors and successors are permuted freely.)
Summing over and swapping order of summation:
(1 mark.)
For a fixed permutation , the inner sum telescopes: adding players one at a time from to gives
(2 marks — telescoping is the key step.)
Hence . (1 mark.)
(b) Linear model closed form — 5 marks
Under independence, . (2) So . (1) The marginal contribution of is — independent of . (1) Since Shapley weights sum to 1,
Interpretation: attribution = weight × deviation of feature from its baseline mean — "input×(weight,centered)". (1)
(c) Superposition & JL — 6 marks
JL lemma: for points, distortion , a random projection into
dimensions preserves all pairwise distances up to factor . (2 marks — statement + bound.)
Consequence: near-orthogonal directions fit in dims — exponentially more concepts than neurons. (1)
Misleading single-neuron Shapley: if concept is spread across many neurons (superposition), no single neuron "is" the concept; splits credit across a distributed code, and a neuron carrying parts of several concepts yields an attribution that cannot be read as "concept 's importance." The attribution is well-defined for the neuron but not for the human concept, because the concept→neuron map is many-to-many. (3 marks: distributed code + polysemantic neuron + interpretation gap.)
(d) LIME vs SHAP — 5 marks
Failure mode (any valid): with correlated/interacting features, LIME's locally-fit linear surrogate weights depend on the sampling kernel and perturbation distribution; a strongly interacting feature can receive near-zero surrogate weight if perturbations rarely toggle it jointly, whereas SHAP's game-theoretic averaging assigns it non-zero credit. (3) LIME may violate local accuracy/efficiency (surrogate intercept + weights need not sum to ) and/or consistency. (2)
Question 2
(a) Grad-CAM derivation — 8 marks
- Neuron importance weight: where . This is global average pooling of the gradients: it measures how much the score increases per unit increase averaged over the whole feature map, giving a single scalar "how important is channel ." (3)
- normalises so weights are comparable across maps of different spatial size (average, not sum). (1)
- Linear combination forms a weighted sum of activation maps — a coarse heatmap at conv resolution, upsampled to input size. (2)
- Final keeps only features with positive influence on the class of interest (negative values correspond to evidence for other classes and would clutter localisation). (2)
(b) Reduction to CAM — 6 marks
Head: . (2) Then
(2) So
Up to the constant , the Grad-CAM weight equals the classifier weight — exactly the CAM formulation. (2)
(c) Model-randomization sanity check — 6 marks
def parameter_randomization_test(model, x, saliency_fn):
S0 = saliency_fn(model, x) # explanation for trained model
sims = []
for layer in top_to_bottom(model.layers):
randomize_weights(layer) # cascading randomization
S = saliency_fn(model, x)
sims.append(similarity(S0, S)) # SSIM / rank correlation
return sims
Pass criterion: as parameters are randomized, saliency should change substantially (similarity → low). If the map is invariant to randomized weights, it is essentially an edge/input detector, not model-explaining → fail. (3)
Probabilistic reasoning: a trustworthy explanation should be a function of the learned conditional ; if it is invariant to it carries no information about the model's decision function, i.e. mutual information . Passing (high sensitivity to ) is necessary for the map to reflect what the model actually computes. (3)
Question 3
(a) Activation patching definition — 6 marks
Run corrupted input but replace the activation with the clean value ; let resulting logit be . Normalised patching effect:
(3) means that activation alone restores the clean answer; means it is irrelevant.
Causal, not correlational: we intervene (-operation) on an internal variable and measure the change in output while holding everything else at the corrupted state. Unlike attention weights or probe accuracy (which only correlate with a concept), patching establishes that the activation causes the behaviour. (3)
(b) Probing pitfall proof — 6 marks
Counterexample: let , output . Suppose concept and is present in the representation (perhaps written by an earlier layer) but the readout weight on is . (2) A linear probe achieves accuracy for . (2) Yet : intervening on (activation patching along ) leaves unchanged — zero causal effect. Thus decodability usage. Patching is stronger because it tests the causal path, not mere presence of information. (2)
(c) Counterfactual gradient — 6 marks
, , . (1)
(2) For : (subgradient, componentwise; at ). (1)
(1) Sparsity: the subgradient has constant magnitude toward regardless of distance, so a feature is only moved if the data-term gradient's magnitude on it exceeds the pull; features with small stay at . This is the same LASSO thresholding mechanism → few features change. (1)
[
{"claim":"Shapley efficiency: for a 2-player game sum of phi equals v(N)-v(empty)",
"code":