peal.teachers.spray_teacher

SpRAy teacher: find confounded samples by clustering LRP attributions.

Spectral Relevance Analysis (SpRAy) computes layer-wise relevance attributions of a classifier over the dataset, clusters them per class with corelay’s spectral clustering pipeline, and serves the result in a ViReLay web GUI. A human selects the clusters that show a confounding (Clever-Hans) feature and exports them; the teacher turns those selections into per-sample group labels that downstream adaptors (e.g. ClArC or GroupDRO) can train against. All intermediate HDF5 databases are written under base_dir.

Functions

append_attributions

Write a batch of attributions, predictions, labels and splits at index.

append_inputs

Write a batch of inputs, labels and filenames at row index.

create_attribution_database

Create an HDF5 attribution database in the ViReLay layout.

create_input_database

Create an HDF5 file with resizable data, label and filenames sets.

resize_attribution_db

Truncate the attribution database's datasets to new_size rows.

resize_input_db

Truncate the input database's datasets to new_size rows.

Classes

Flatten

corelay processor flattening each sample to a vector.

LogitDifference

Module returning y[0] - y[1]; a binary logit-difference head.

Normalize

corelay processor dividing each sample by its total sum.

Spray

Teacher that derives confounder group labels from a SpRAy analysis.

SprayConfig

Config for the Spray teacher.

SumChannel

corelay processor summing attributions over the channel axis.