peal.teachers.preclustered_teacher.PreclusteredTeacher¶
- class peal.teachers.preclustered_teacher.PreclusteredTeacher[source]¶
Bases:
TeacherInterfaceFeedback source that labels a counterfactual by its cluster membership.
A counterfactual is
"true"when its cluster id is incorrect_clustersand"false"otherwise; the usual sanity gates (student already wrong, not flipped, out of distribution) are applied first.- Parameters:
dataset (
PealDataset) – Dataset used for the outlier score (calculate_outlier_score) and, at high tracking levels, for rendering contrastive collages.correct_clusters (
collectionofint) – Cluster ids whose counterfactuals count as valid explanations.tracking_level (
int, optional) – Verbosity; at 5 or above a collage of every feedback batch is written.counterfactual_type (
str, optional) –"1sided"(default) rejects counterfactuals of samples the student misclassified in the first place; any other value skips that gate.
Methods
Return one feedback string per counterfactual.
- __init__(dataset, correct_clusters, tracking_level=0, counterfactual_type='1sided')[source]¶
Store the dataset, the correct cluster ids and the tracking options.
- get_feedback(x_counterfactual_list, y_source_list, x_list, y_list, y_target_end_confidence_list, cluster_list, base_dir=None, y_target_list=None, mode='train', **kwargs)[source]¶
Return one feedback string per counterfactual.
- Parameters:
x_counterfactual_list (
sequenceoftorch.Tensor) – Counterfactual inputs, each without batch dimension.y_source_list (
sequenceofint) – Class the predictor assigned to the original sample.x_list (
sequenceoftorch.Tensor) – Original samples; only forwarded to the collage writer.y_list (
sequenceofint) – Ground-truth labels of the original samples.y_target_end_confidence_list (
sequenceoffloat) – Predictor confidence in the target class after the edit.cluster_list (
sequenceofint) – Cluster id of every counterfactual, as stamped byCounterfactualExplainer.cluster_explanations.base_dir (
str, optional) – Directory the collages are written to whentracking_level >= 5.y_target_list (
sequenceofint, optional) – Target classes, forwarded to the collage writer.mode (
str, optional) –"train"or"validation"; collages are written for both.**kwargs – Passed through to
dataset.generate_contrastive_collage.
- Returns:
Per counterfactual, in order of precedence:
"student originally wrong!"(1sided andy != y_source),"student not swapped!"(target confidence below 0.5),"ood_<score>"(relative outlier score above 4.0), else"true"or"false"by cluster membership.- Return type:
Notes
The teacher labels handed to the collage writer are
-1placeholders; this teacher never relabels the images themselves.