peal.teachers.llm2model_teacher¶
LLM-in-the-loop teacher.
LLM2ModelTeacher is a drop-in replacement for Human2ModelTeacher: it answers the same visual counterfactual-feedback questions, but instead of a human clicking the Flask GUI it shells out to a headless Claude Code process (claude -p –output-format json). This lets DiDAE / CFKD runs that would otherwise block on a browser run fully unattended, while keeping the shape of human feedback so a real human (teacher: human@8000) can be swapped back in without any other change.
Each collage handed to the teacher is a side-by-side grid: the LEFT half is the original image, the RIGHT half is the counterfactual (see DiDAE._collect_direction_collages, which saves torch.cat([orig, cf]) with nrow=2). The teacher’s job, per collage, is the same judgement a human makes:
"true" – the edit changed the class-defining (target) feature: a valid
counterfactual
"false" – the edit changed the spurious / confounding feature instead
"ood" – the edited image is not a plausible, in-distribution image
The claude binary is expected on PATH inside the run environment. Under the lab’s appruns Apptainer wrapper it is bind-mounted to /usr/local/bin/claude and authenticated from the mounted ~/.claude credentials, so no API key is needed.
Classes
Teacher that labels counterfactual collages with a headless Claude call. |