peal.teachers.spray_teacher.Spray

class peal.teachers.spray_teacher.Spray[source]

Bases: TeacherInterface

Teacher that derives confounder group labels from a SpRAy analysis.

The constructor loads the classifier (unwrapping a .model attribute if present), loads the train/val/test datasets with URLs and groups enabled, and prepares base_dir. get_feedback() then runs the attribution, clustering and ViReLay steps and returns a filename -> group-label map.

Parameters:
Variables:
  • analysis_dir (str) – <base_dir>/attrbs-layer-<n>_analysis, set by get_feedback.

  • analysis_db_path (attribution_db_path, heatmaps_db_path, concept_importance_db_path, input_db_path,) – HDF5 files produced by the analysis.

Methods

get_feedback

Run the full SpRAy pipeline and return per-sample confounder labels.

__init__(config, device=None)[source]

Load the classifier and the datasets and create base_dir.

Scalar tsne_perplexity/umap_neighbors entries are wrapped in a list, the model is unwrapped (model.model) and put in eval mode, and the train/val/test datasets are loaded with URLs and groups enabled and class restrictions disabled, so that every sample can be attributed and matched back to its file. The HDF5 paths are only set later, by get_feedback().

Parameters:
  • config (dict or SprayConfig) – See SprayConfig; a dict is validated into one.

  • device (str, optional) – Torch device; CUDA when available by default.

get_feedback(**args)[source]

Run the full SpRAy pipeline and return per-sample confounder labels.

Steps: compute attributions into HDF5 databases, spectrally cluster them per class, write a label map and ViReLay project, run the GUI until the user has exported <cls>-confounders.json / <cls>-nonconfounders.json into group-labels/ (the process exits and must be re-run after that), then read the selections. Side effects: config.yaml, data_spray_labels.csv (the dataset’s data.csv plus a SprayLabel column, -1 for unlabelled) and result_summary.txt (label accuracy against has_confounder) under analysis_dir.

Parameters:

**args – Ignored; present for the TeacherInterface signature.

Returns:

Sample filename -> 1 (confounder selected) or 0 (non-confounder).

Return type:

dict of str to int

Raises:

ImportError – If the optional h5py dependency is not installed.