peal.teachers.teacher_factory.get_teacher

peal.teachers.teacher_factory.get_teacher(teacher, output_size, adaptor_config, dataset, device=torch.device, tracking_level=0, counterfactual_type='1sided')[source]

Build the teacher described by teacher.

The accepted specifications are, in dispatch order:

  • a TeacherInterface instance, returned unchanged;

  • an nn.Module, wrapped as an eval-mode Model2ModelTeacher;

  • a dict with type: symbolic (model path, confounder_name), type: llm (LLM2ModelTeacher driven by a claude -p subprocess), type: web (WebFeedbackTeacher polling a directory) or type: NoisyModel2Model (model path, noise_prob);

  • strings "web:<dir>", "preclustered" (uses adaptor_config.correct_clusters), "cluster[XXXX]", "virelay[XXXX]", "human[XXXX]" (XXXX an optional four digit port, default 8000), "SegmentationMask" (uses adaptor_config.attribution_threshold), "Baseline:<strategy>" and a *.cpl path to a torch-saved oracle model.

Saved models are loaded with torch.load and fall back to weights_only=False when the default load fails.

Parameters:
  • teacher (TeacherInterface or nn.Module or str or dict) – Teacher specification as listed above.

  • output_size (int) – Number of classifier outputs. Currently unused by every branch.

  • adaptor_config (object) – Adaptor config; only correct_clusters and attribution_threshold are read, for the preclustered and segmentation-mask teachers.

  • dataset (PealDataset) – Dataset the teacher judges counterfactuals of.

  • device (torch.device or str, optional) – map_location for torch.load. Defaults to CPU.

  • tracking_level (int, optional) – Verbosity of intermediate artifacts, forwarded to the teacher.

  • counterfactual_type (str, optional) – "1sided" or "2sided", forwarded to the teacher.

Returns:

The constructed teacher.

Return type:

TeacherInterface

Raises:

ValueError – If teacher matches none of the specifications.