peal.teachers.symbolic_teacher.SymbolicTeacher¶
- class peal.teachers.symbolic_teacher.SymbolicTeacher[source]¶
Bases:
TeacherInterfaceTeacher 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 determinesself.device.dataset – Dataset exposing
attributes, the ordered list of feature names.confounder_name (
str) – Name of the confounder feature; must be indataset.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_nameis not among the dataset attributes.
Methods
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_nameis not indataset.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 (
sequenceoftorch.Tensor) – Counterfactual feature vectors, each of shape(num_features,).y_source_list (
sequenceofint) – Class predicted by the student for the original sample.x_list (
sequenceoftorch.Tensor) – Original feature vectors matchingx_counterfactual_list.y_list (
sequenceofint) – Ground-truth labels of the originals.y_target_end_confidence_list (
sequenceoffloat) – Student confidence in the target class after the edit.base_dir (optional) – Unused; kept for interface compatibility.
y_target_list (
sequenceofint, 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 reachy_target),"not flipped"(teacher model keeps its class),"false"(flip explained by the confounder alone) or"true".- Return type:
Notes
The model is switched to eval mode for the duration of the call and restored afterwards.