peal.teachers.virelay_teacher.VirelayTeacher

class peal.teachers.virelay_teacher.VirelayTeacher[source]

Bases: TeacherInterface

Human teacher whose verdicts come from a ViReLay cluster selection.

Parameters:
  • port (int) – First port for the ViReLay server; incremented while occupied.

  • dataset (peal.data.datasets.ImageDataset, optional) – Unused by this teacher beyond being stored.

  • tracking_level (int) – Verbosity level of the surrounding run (stored only).

  • num_classes (int) – Stored only; the analysis currently runs with a single class.

  • teacher_config (str) – Yaml with meta_analysis_variant, number_of_eigenvalues, number_of_clusters_list, number_of_neighbors, dataset_down_sampling_method and dataset_up_sampling_method.

  • distance_from_last_layer (int) – Which intermediate student output (counted from the end, see get_intermediate_output) the relevance vectors are taken from.

Methods

get_feedback

Build a ViReLay project for the flipped counterfactuals and collect verdicts.

__init__(port=2000, dataset=None, tracking_level=5, num_classes=2, teacher_config='configs/cfkd_experiments/teachers/virelay_teacher.yaml', distance_from_last_layer=27)[source]

Store the settings and load teacher_config; see the class docstring.

get_feedback(collage_path_list, x_counterfactual_list, x_list, y_list, base_dir, student, y_source_list, y_target_end_confidence_list, **kwargs)[source]

Build a ViReLay project for the flipped counterfactuals and collect verdicts.

Only counterfactuals with y_target_end_confidence > 0.5 are shown. For each of them the difference of the student’s intermediate output (layer distance_from_last_layer) between counterfactual and factual is summed spatially and L1-normalised over channels to form a [1, C, 1, 1] relevance vector. base_dir is wiped and filled with collage_greater_than_05/, database.hdf5, attribution_database.hdf5, analysis.hdf5 and analysis.yaml (each step is skipped if its file already exists), then ViReLay is served until feedback.json appears.

Parameters:
  • collage_path_list (list of str) – Collage image per counterfactual.

  • x_counterfactual_list (list of torch.Tensor) – Counterfactual inputs.

  • x_list (list of torch.Tensor) – Factual inputs.

  • y_list (list) – Labels and source classes; currently not used for the analysis.

  • y_source_list (list) – Labels and source classes; currently not used for the analysis.

  • base_dir (str) – Working directory for the ViReLay project (recreated).

  • student (torch.nn.Module) – The classifier whose intermediate activations are attributed.

  • y_target_end_confidence_list (list of float) – Target-class confidence of every counterfactual.

  • **kwargs – Further tracked values, ignored.

Returns:

One entry per input counterfactual: "false" if its index was in selectedDataPointIndices of the feedback file, "true" for the other shown ones and "Student not flipped" for those with confidence at most 0.5.

Return type:

list of str