peal.teachers.baseline_teacher.BaselineTeacher¶
- class peal.teachers.baseline_teacher.BaselineTeacher[source]¶
Bases:
TeacherInterfaceContent-agnostic teacher used as a baseline for CFKD experiments.
The feedback for every counterfactual is decided by
strategywithout looking at the sample, unless the counterfactual is disqualified first (student originally wrong on a one-sided counterfactual, or student not swapped to the target class).- Parameters:
strategy (
{"random", "true", "false"}) –"random"draws a fair coin per counterfactual,"true"and"false"always give that verdict.dataset (
peal dataset, optional) – Only needed fortracking_level >= 5; itsgenerate_contrastive_collageis used to render the feedback.tracking_level (
int) – Verbosity level;>= 5writes collage images tobase_dir.counterfactual_type (
{"1sided", "2sided"}) – With"1sided"a counterfactual whose original prediction was wrong gets the feedback"student originally wrong!".
Methods
Produce one feedback string per counterfactual.
- get_feedback(x_counterfactual_list, y_source_list, x_list, y_list, y_target_end_confidence_list, base_dir=None, y_target_list=None, student=None, **kwargs)[source]¶
Produce one feedback string per counterfactual.
- Parameters:
x_counterfactual_list (
listoftorch.Tensor) – Counterfactual images.y_source_list (
list) – Class the student predicted for each original sample.x_list (
listoftorch.Tensor) – Original images.y_list (
list) – Ground-truth labels of the originals.y_target_end_confidence_list (
listoffloat) – Student confidence for the target class on the counterfactual.base_dir (
str, optional) – Directory the collage is written to whentracking_level >= 5.y_target_list (
list, optional) – Target class of each counterfactual.student (
torch.nn.Module) – The classifier being explained; only used to determine the device.**kwargs – Forwarded to
dataset.generate_contrastive_collage.
- Returns:
One of
"true","false","student originally wrong!"or"student not swapped!"per counterfactual.- Return type: