peal.teachers.model2model_teacher.NoisyModel2ModelTeacher

class peal.teachers.model2model_teacher.NoisyModel2ModelTeacher[source]

Bases: Model2ModelTeacher

Model-to-model teacher that flips a fraction of its verdicts.

Simulates an unreliable annotator: whenever the reference model reaches a "true"/"false" verdict, it is inverted with probability noise_prob. The rejection reasons are left untouched. Unlike the parent, this variant also rejects out-of-distribution edits ("ood_<score>" above a relative outlier score of 2.5) and edits that moved the student somewhere other than the target class ("adversarial counterfactual!").

Parameters:

Methods

get_feedback

Return one verdict per counterfactual.

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

Initialise the base teacher and store the label-flip probability.

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]

Return one verdict per counterfactual.

Parameters:
  • x_counterfactual_list (sequence of torch.Tensor) – Counterfactual images of shape (C, H, W), aligned with x_list.

  • y_source_list (sequence) – The student’s predicted class for each original image.

  • x_list (sequence of torch.Tensor) – The original images.

  • y_list (sequence) – Ground-truth labels of the original images.

  • y_target_end_confidence_list (sequence of float) – The student’s confidence in the target class after the edit; a value below 0.5 means the edit failed to flip the student.

  • base_dir (str, optional) – Directory the contrastive collage is written to.

  • y_target_list (sequence, optional) – The class each counterfactual was steered towards.

  • student (torch.nn.Module, optional) – The classifier under repair; used for the logged before/after predictions.

  • mode (str, optional) – "train" or "validation"; only selects whether a collage is produced.

  • **kwargs – Forwarded to dataset.generate_contrastive_collage.

Returns:

One verdict per counterfactual, in input order.

Return type:

list of str