peal.teachers.virelay_teacher.VirelayTeacher¶
- class peal.teachers.virelay_teacher.VirelayTeacher[source]¶
Bases:
TeacherInterfaceHuman 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 withmeta_analysis_variant,number_of_eigenvalues,number_of_clusters_list,number_of_neighbors,dataset_down_sampling_methodanddataset_up_sampling_method.distance_from_last_layer (
int) – Which intermediate student output (counted from the end, seeget_intermediate_output) the relevance vectors are taken from.
Methods
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.5are shown. For each of them the difference of the student’s intermediate output (layerdistance_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_diris wiped and filled withcollage_greater_than_05/,database.hdf5,attribution_database.hdf5,analysis.hdf5andanalysis.yaml(each step is skipped if its file already exists), then ViReLay is served untilfeedback.jsonappears.- Parameters:
collage_path_list (
listofstr) – Collage image per counterfactual.x_counterfactual_list (
listoftorch.Tensor) – Counterfactual inputs.x_list (
listoftorch.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 (
listoffloat) – Target-class confidence of every counterfactual.**kwargs – Further tracked values, ignored.
- Returns:
One entry per input counterfactual:
"false"if its index was inselectedDataPointIndicesof the feedback file,"true"for the other shown ones and"Student not flipped"for those with confidence at most 0.5.- Return type: