peal.teachers.baseline_teacher.BaselineTeacher

class peal.teachers.baseline_teacher.BaselineTeacher[source]

Bases: TeacherInterface

Content-agnostic teacher used as a baseline for CFKD experiments.

The feedback for every counterfactual is decided by strategy without 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 for tracking_level >= 5; its generate_contrastive_collage is used to render the feedback.

  • tracking_level (int) – Verbosity level; >= 5 writes collage images to base_dir.

  • counterfactual_type ({"1sided", "2sided"}) – With "1sided" a counterfactual whose original prediction was wrong gets the feedback "student originally wrong!".

Methods

get_feedback

Produce one feedback string per counterfactual.

__init__(strategy='random', dataset=None, tracking_level=0, counterfactual_type='1sided')[source]
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 (list of torch.Tensor) – Counterfactual images.

  • y_source_list (list) – Class the student predicted for each original sample.

  • x_list (list of torch.Tensor) – Original images.

  • y_list (list) – Ground-truth labels of the originals.

  • y_target_end_confidence_list (list of float) – Student confidence for the target class on the counterfactual.

  • base_dir (str, optional) – Directory the collage is written to when tracking_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:

list of str