Interpretability artifacts¶
The shared interpretability module defines the validated adapter-to-renderer contract. Method-specific score extraction remains inside each adapter.
interpretability
¶
Typed patch-evidence artifacts and coordinate-aware heatmap rendering.
The benchmark deliberately uses the term evidence rather than calling every map attention. Adapters identify the native quantity they expose (pooling attention, prompt relevance, patch probability, and so on), while this module only validates, serializes, and renders those quantities.
PatchEvidence
dataclass
¶
PatchEvidence(
scores: Tensor,
score_type: str,
description: str,
scale: str = "patch",
feature_path_key: str = "feature_path_column",
class_index: int | None = None,
native: bool = True,
coordinates: Tensor | None = None,
index_order: str = "feature_rows",
)
One patch-aligned explanation emitted by a method adapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scores
|
Tensor
|
One finite scalar per patch. |
required |
score_type
|
str
|
Precise semantic name, such as |
required |
description
|
str
|
Human-readable definition of the score. |
required |
scale
|
str
|
Scale label used in filenames and figures. |
'patch'
|
feature_path_key
|
str
|
Config key whose value names the manifest feature column for this scale. |
'feature_path_column'
|
class_index
|
int | None
|
Class queried by a class-specific score, if applicable. |
None
|
native
|
bool
|
Whether the score is computed by the released architecture. |
True
|
coordinates
|
Tensor | None
|
Optional level-0 |
None
|
index_order
|
str
|
Patch ordering convention. |
'feature_rows'
|
validated
¶
Return a detached CPU copy after enforcing the artifact contract.
Source code in common/interpretability.py
InterpretabilityResult
dataclass
¶
InterpretabilityResult(
logits: Tensor,
evidence: Sequence[PatchEvidence],
notes: Sequence[str] = tuple(),
)
Prediction plus one or more faithful patch-evidence maps.
validated
¶
Validate class scores and every patch-evidence payload.
Source code in common/interpretability.py
CoordinateBag
dataclass
¶
CoordinateBag(
coordinates: ndarray,
patch_size_level0: int,
level0_width: int,
level0_height: int,
)
Level-0 coordinates and geometry read from one feature HDF5.
load_coordinate_bag
¶
load_coordinate_bag(path: str | Path) -> CoordinateBag
Read aligned level-0 coordinates without loading feature vectors.
Source code in common/interpretability.py
align_coordinates
¶
align_coordinates(
bag: CoordinateBag,
score_count: int,
*,
max_patches: int | None = None,
index_order: str = "feature_rows",
region_span_level0: int | None = None,
) -> ndarray
Align stored coordinates with deterministic evaluation-time sampling.
Source code in common/interpretability.py
render_heatmap
¶
render_heatmap(
scores: ndarray,
coordinates: ndarray,
geometry: CoordinateBag,
output: str | Path,
*,
wsi_path: str | Path | None = None,
alpha: float = 0.55,
max_size: int = 2048,
percentile_range: tuple[float, float] = (1.0, 99.0),
) -> Path
Render patch evidence on a thumbnail or a coordinate-only canvas.
Source code in common/interpretability.py
write_evidence_table
¶
write_evidence_table(
evidence: PatchEvidence,
coordinates: ndarray,
output: str | Path,
) -> Path
Write lossless patch scores and coordinates as a CSV artifact.
Source code in common/interpretability.py
write_manifest
¶
Write the interpretation sidecar with stable formatting.