peal.teachers.symbolic_teacher.SymbolicTeacher

class peal.teachers.symbolic_teacher.SymbolicTeacher[source]

Bases: TeacherInterface

Teacher that judges tabular counterfactuals by reverting one confounder.

For every counterfactual the confounder column is set back to its original value; if that alone restores the reference model’s original prediction the class change was driven solely by the confounder and the counterfactual is flagged "false", otherwise "true".

Parameters:
  • model (torch.nn.Module) – Reference classifier (the “teacher” model) mapping a feature vector of shape (num_features,) to class logits. Its device determines self.device.

  • dataset – Dataset exposing attributes, the ordered list of feature names.

  • confounder_name (str) – Name of the confounder feature; must be in dataset.attributes.

  • tracking_level (int, optional) – Stored only; not used by this teacher.

  • counterfactual_type (str, optional) – "1sided" (default) additionally rejects samples the student already misclassified before the edit.

Variables:

confounder_idx (int) – Column index of the confounder inside the feature vector.

Raises:

ValueError – If confounder_name is not among the dataset attributes.

Methods

get_feedback

Label every counterfactual as "true", "false" or a rejection.

__init__(model, dataset, confounder_name, tracking_level=0, counterfactual_type='1sided')[source]

Resolve the confounder column index and the reference model’s device.

Raises:

ValueError – If confounder_name is not in dataset.attributes.

Parameters:

confounder_name (str)

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, mode='train', **kwargs)[source]

Label every counterfactual as "true", "false" or a rejection.

Parameters:
  • x_counterfactual_list (sequence of torch.Tensor) – Counterfactual feature vectors, each of shape (num_features,).

  • y_source_list (sequence of int) – Class predicted by the student for the original sample.

  • x_list (sequence of torch.Tensor) – Original feature vectors matching x_counterfactual_list.

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

  • y_target_end_confidence_list (sequence of float) – Student confidence in the target class after the edit.

  • base_dir (optional) – Unused; kept for interface compatibility.

  • y_target_list (sequence of int, optional) – Target class of every counterfactual.

  • student (torch.nn.Module) – The classifier being repaired; required despite the default.

  • mode (str, optional) – Unused; kept for interface compatibility.

Returns:

One entry per counterfactual, in order of precedence: "student originally wrong!" (1-sided mode, student label differs from ground truth), "teacher originally wrong!", "student not swapped!" (confidence below 0.5), "adversarial counterfactual!" (student flipped but the edit did not reach y_target), "not flipped" (teacher model keeps its class), "false" (flip explained by the confounder alone) or "true".

Return type:

list of str

Notes

The model is switched to eval mode for the duration of the call and restored afterwards.