6.3.11Interpretability & Explainability

Concept-based explanations

2,189 words10 min readdifficulty · medium

What Are Concept-based Explanations?

The shift:

  • Feature attribution → "Pixel (x, y) contributed +0.8 to the output."
  • Concept-based → "The presence of 'stripes' contributed +2.3 to classifying this as a zebra."

How It Works: Deriving TCAV (Testing with Concept Activation Vectors)

TCAV (Kim et al., 2018) is the canonical concept-based method. Let's build it from scratch.

Step 1: What is a Concept Activation Vector (CAV)?

Suppose we want to test if a model uses the concept "striped."

  1. Gather concept examples: Collect images with stripes (P) and random images without stripes (N).
  2. Extract activations: Feed both sets through the model, extract activations at layer \ell: hRd\mathbf{h}_\ell \in \mathbb{R}^d.
  3. Train a linear classifier: Learn a hyperplane separating P from N in activation space:
vc=argminwiPNL(wh(i),yi)+λw2\mathbf{v}_c = \arg\min_{\mathbf{w}} \sum_{i \in P \cup N} \mathcal{L}(\mathbf{w}^\top \mathbf{h}_\ell^{(i)}, y_i) + \lambda \|\mathbf{w}\|^2

where yi=+1y_i = +1 for concept examples, 1-1 for random. The normal vector vc\mathbf{v}_c (after normalization) is the CAV — it points in the "striped" direction in activation space.

Why this works: If the model represents "stripes" internally, striped images cluster in activation space. The CAV captures that clustering direction.


Step 2: Measuring Concept Sensitivity

Now we test: Does the model's prediction for class kk depend on concept cc?

Define the directional derivative of the logit Sk(x)S_k(\mathbf{x}) for class kk w.r.t. the concept:

TCAV,c,k=ExXk[1{hSk(x)vc>0}]\text{TCAV}_{\ell, c, k} = \mathbb{E}_{\mathbf{x} \in X_k} \left[ \mathbb{1}\left\{ \nabla_{\mathbf{h}_\ell} S_k(\mathbf{x}) \cdot \mathbf{v}_c > 0 \right\} \right]

Breaking it down:

  • hSk(x)\nabla_{\mathbf{h}_\ell} S_k(\mathbf{x}): gradient of class kk's logit w.r.t. layer \ell activations. This tells us "how to change h\mathbf{h}_\ell to increase SkS_k."
  • hSkvc\nabla_{\mathbf{h}_\ell} S_k \cdot \mathbf{v}_c: dot product. If positive, moving h\mathbf{h}_\ell toward the concept direction increases SkS_k.
  • 1{>0}\mathbb{1}\{\cdot > 0\}: binary indicator. We count the fraction of examples where the concept positively influences the class.

Why the expectation? We test on multiple examples of class kk (e.g., many zebra images) to avoid noise from a single sample.


Step 3: Statistical Significance

Run TCAV with multiple random concept sets (same size as P, drawn from N). If the real CAV's score is significantly higher than random, the concept is genuinely used.

p=1+i=1n1{TCAVrandom,iTCAVc}n+1p = \frac{1 + \sum_{i=1}^{n} \mathbb{1}\{\text{TCAV}_{\text{random}, i} \geq \text{TCAV}_{c}\}}{n + 1}

Typical threshold: p<0.05p < 0.05.


Worked Example: "Striped" for Zebra Classification

Setup: ImageNet classifier, class kk = zebra, concept cc = "striped."

  1. Collect concept examples: 50 images with stripes (tigers, barcode patterns, striped shirts), 50 random ImageNet images.
  2. Extract activations: Use layer mixed5c (Inception V3). Each image → hR2048\mathbf{h} \in \mathbb{R}^{2048}.
  3. Train CAV: Logistic regression on the 100 activations. Get vstripedR2048\mathbf{v}_{\text{striped}} \in \mathbb{R}^{2048}.
  4. Test on zebras: Take 100 zebra images. For each:
    • Compute hSzebra(x)\nabla_{\mathbf{h}} S_{\text{zebra}}(\mathbf{x}) via backprop.
    • Check if hSzebravstriped>0\nabla_{\mathbf{h}} S_{\text{zebra}} \cdot \mathbf{v}_{\text{striped}} > 0.
  5. Result: 87% of zebras have positive directional derivative → TCAV=0.87\text{TCAV} = 0.87.
  6. Compare to random: Run 20 random CAVs → mean TCAV = 0.52, std = 0.08. The score 0.87 is 0.870.520.084.4σ\frac{0.87 - 0.52}{0.08} \approx 4.4\sigma away → p<0.001p < 0.001. Conclusion: The model genuinely uses "stripes" to classify zebras.

Why this step? Without statistical testing, a TCAV of 0.6 could be noise. The random baseline controls for spurious correlations in activation space.


Figure — Concept-based explanations

ACE: Automated Concept Extraction

How it works:

  1. Segment inputs: Use image segmentation (e.g., SLIC superpixels) to extract patches.
  2. Cluster activations: Run k-means on layer activations of all patches. Each cluster = a discovered concept.
  3. Name concepts: Manually inspect cluster examples or use a captioning model.
  4. Run TCAV: Test each discovered concept's importance via TCAV.

Advantage: Fully data-driven. Discovers concepts you didn't think to test (e.g., "model uses background grass to classify cows").

Limitation: Cluster quality depends on segmentation. Semantic meaning isn't guaranteed.


Common Mistakes


Connections

  • Feature Attribution Methods — Concept-based explanations complement pixel-level saliency by adding semantic meaning.
  • Layer-wise Relevance Propagation — LRP traces importance to inputs; TCAV traces importance to concepts.
  • Adversarial Examples — Concept-based methods can reveal spurious concepts the model exploits (e.g., "watermark" in medical images).
  • Model Editing — Once you identify harmful concepts (via TCAV), you can ablate the corresponding CAV directions.
  • Probing Classifiers — Both probe representation spaces, but probing asks "is concept X encoded?" while TCAV asks "is X used for decision Y?"

Key Takeaways

  1. Concept-based explanations translate model internals into human semantics.
  2. TCAV measures concept importance via directional derivatives of class logits.
  3. Statistical testing (random CAVs) is mandatory to avoid false positives.
  4. ACE automates concept discovery via clustering, but trades control for coverage.
  5. Concepts must be atomic (single semantic) and causally tested (not just present).

Recall Explain to a 12-year-old

Imagine you're teaching a robot to recognize animals. You show it pictures, and it learns on its own. Later, you ask: "When you see a zebra, what do you look for? Stripes? The shape? The background?"

But the robot doesn't speak English! Its brain is just a bunch of numbers. So we use a trick:

  1. Show the robot lots of striped things (flags, tigers, barcodes).
  2. Look at its brain's numbers when it sees stripes.
  3. Find the "direction" in its brain that means "stripy."
  4. Test: When the robot sees a zebra, does changing its brain toward "stripy" make it more confident it's a zebra? If yes → the robot uses stripes! If no → maybe it's looking at something else (like grass). This is like giving the robot a vocabulary test for concepts we understand.


Flashcards

#flashcards/ai-ml

What is the key difference between feature attribution and concept-based explanations?
Feature attribution explains predictions using raw input features (pixels, tokens); concept-based methods use high-level semantic concepts (e.g., "stripes," "metal") defined by humans.
What is a Concept Activation Vector (CAV)?
A unit vector in a neural network's activation space that points in the direction corresponding to a human-defined concept, learned by training a linear classifier to separate concept examples from non-examples.
What does the TCAV score measure?
The fraction of examples in class kk for which the directional derivative of the class logit w.r.t. layer activations has a positive dot product with the concept vector vc\mathbf{v}_c. Measures if increasing the concept increases the class probability.
Why must TCAV be compared against random CAVs?
In high-dimensional spaces, random vectors can have non-zero alignment with gradients by chance. Random baselines distinguish true concept usage from noise.
What is ACE and how does it differ from TCAV?
ACE (Automated Concept-based Explanations) automatically discovers concepts via clustering in activation space, whereas TCAV requires manually curated concept example sets.
Why should concepts be atomic in concept-based explanations?
Atomic concepts (single semantic meaning) allow precise identification of what the model uses. Mixing concepts (e.g., "stripes-and-color") prevents isolating which feature drives predictions.
What does hSk(x)vc>0\nabla_{\mathbf{h}_\ell} S_k(\mathbf{x}) \cdot \mathbf{v}_c > 0 mean in TCAV?
Moving the activation h\mathbf{h}_\ell in the direction of concept cc increases the logit for class kk, meaning the model uses concept cc to predict class kk for input x\mathbf{x}.
What is the typical TCAV score range and interpretation?
TCAV scores range from 0 to 1. Near 1 means the concept strongly influences the class; near 0 means it's irrelevant or opposed; ~0.5 suggests randomness (no relationship).
How does ACE discover concepts automatically?
ACE segments inputs into patches, extracts activations, clusters them (e.g., k-means), and treats each cluster as a concept. Concepts are then named via inspection or captioning models.
Why might a model classify zebras without using "stripes"?
The model may exploit spurious correlations (e.g., "savanna background" or "four-legged silhouette") if those features are statistically predictive in the training data. TCAV reveals such alternate strategies.

Concept Map

limited to

shows where not what

solved by

use

canonical method

examples P and N

train linear classifier

dot product with

sign counted over class

fraction positive

averaged via

Feature attribution

Raw input features

Semantic gap

Concept-based explanations

Human concepts stripes furriness

TCAV Kim 2018

Layer activations h_l

Concept Activation Vector v_c

Gradient of logit S_k

TCAV score

Concept sensitivity for class k

Expectation over examples

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Concept-based explanations ka main idea yeh hai ki model ko samajhne ke liye hum pixels ya numbers ki jagah insaan ke samajhne wale concepts use karein. Jaise agar ek model zebra ko classify kar raha hai, toh simple question hai: kya woh "stripes" dekh raha hai ya background ka grass dekh raha hai? TCAV (Testing with Concept Activation Vectors) ek method hai jisme hum pehle concept ki examples collect karte hain—jaise striped images—aur phir model ke andar ek "direction" nikalte hain jo us concept ko represent kare. Yeh direction CAV kehlati hai. Phir hum test karte hain: agar model ke activations ko us direction mein move karein, toh kya zebra ka prediction strong hota hai? Agar haan, toh model genuinely "stripes" use kar raha hai.

Iska practical fayda yeh hai ki doctors, engineers, ya regulators model ke decisions ko human terms mein samajh sakte hain. Agar ek medical model "tumor" detect karne ke liye galat concept (jaise image ka watermark) use kar raha ho, toh TCAV se yeh pata chal jayega aur hum fix kar sakte hain. Lekin important hai ki random baseline ke sath compare karein, warna coincidence ko signal samajh lenge. ACE method yeh kaam automatic kar deta hai—clustering se khud concepts discover karta hai—lekin phir bhi human ko check karna padta hai ki discovered concepts meaningful hain ya nahi.

Go deeper — visual, from zero

Test yourself — Interpretability & Explainability

Connections