Interpretability¶
Occlusion sensitivity and related probes.
polyweave.interpretability ¶
Interpretability probes for PolyWeave layers and teachers.
Currently: occlusion sensitivity, used to distinguish additive from multiplicative (Sigma-Pi) features via their conjunctive AND-signature.
conjunction_index ¶
conjunction_index(response_fn: ResponseFn, x: Tensor, group_a: Sequence[int] | Tensor, group_b: Sequence[int] | Tensor, *, baseline: float | Tensor = 0.0, eps: float = 1e-08) -> torch.Tensor
AND-signature index in [0, 1] per item.
index = (drop_a + drop_b - drop_ab) / (|drop_ab| + eps), clamped to
[0, 1]:
- ~0 — additive feature (single drops add up to the joint drop, no interaction).
- ~1 — multiplicative / conjunctive feature (either factor alone already collapses the response, so the single drops far exceed the joint drop).
Returns [N]. Aggregate with .mean() for a per-feature scalar.
Source code in polyweave/interpretability/occlusion.py
group_drops ¶
group_drops(response_fn: ResponseFn, x: Tensor, group_a: Sequence[int] | Tensor, group_b: Sequence[int] | Tensor, *, baseline: float | Tensor = 0.0) -> dict
Single- and joint-occlusion drops for two disjoint feature groups.
Returns a dict with per-item tensors drop_a, drop_b, drop_ab and
interaction = drop_ab - drop_a - drop_b (each [N]). Indices select
along the flattened feature axis.
Source code in polyweave/interpretability/occlusion.py
occlusion_sensitivity_1d ¶
occlusion_sensitivity_1d(response_fn: ResponseFn, x: Tensor, *, baseline: float | Tensor = 0.0, window: int = 1, stride: int = 1) -> torch.Tensor
Per-feature occlusion sensitivity map over the feature axis of x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response_fn
|
ResponseFn
|
maps |
required |
x
|
Tensor
|
input batch |
required |
baseline
|
float | Tensor
|
value substituted into the occluded window (default |
0.0
|
window
|
int
|
width of the occluding window in features. |
1
|
stride
|
int
|
step between successive window starts. |
1
|
Returns:
| Type | Description |
|---|---|
Tensor
|
|
Tensor
|
column per window position |
Tensor
|
response most depends on. |
Source code in polyweave/interpretability/occlusion.py
occlusion_sensitivity_2d ¶
occlusion_sensitivity_2d(response_fn: ResponseFn, x: Tensor, *, baseline: float | Tensor = 0.0, window: int = 3, stride: int = 1, relative: bool = False, eps: float = 1e-08) -> torch.Tensor
Spatial occlusion sensitivity for [N, C, H, W] inputs.
A window x window patch (all channels) is occluded at each spatial stride
position. Returns an [N, Hout, Wout] map of response drops, the classic
Zeiler-Fergus heatmap.
With relative=True each drop is divided by the un-occluded base response
(drop / (base + eps)), giving the fraction of the response that depends
on each region. This is what exposes the AND-signature visually: for a
multiplicative detector every contributing region is ~100% critical (occluding
it alone collapses the response), whereas for an additive detector each region
is only partially critical.