peal.teachers.web_feedback_teacher.WebFeedbackTeacher¶
- class peal.teachers.web_feedback_teacher.WebFeedbackTeacher[source]¶
Bases:
TeacherInterfaceTeacher that collects human verdicts through JSON files in a job directory.
Used by the web demo’s job worker in place of
Human2ModelTeacher. Each call toget_feedback()is one round: the collages that need a verdict are written tofeedback_request_<round>.jsonand the teacher blocks untilfeedback_response_<round>.jsoncontains a complete set of valid verdicts.- Parameters:
feedback_dir (
str) – Directory shared with the web app; created if missing.poll_interval (
float) – Seconds between checks for the response file.timeout_s (
floatorNone) – Give up (TimeoutError) after this many seconds without a complete response;Nonewaits forever.auto_verdict (
strorNone) –"true","false"or"ood"answers every request without a person. Falls back to thePEAL_WEB_FEEDBACK_AUTOenvironment variable whenNone.min_confidence (
float) – Counterfactuals whose target-class end confidence is below this value are answered"student not swapped!"without asking anyone.tracking_level (
int) – Stored for interface compatibility; unused here.counterfactual_type (
str) –"1sided"asks only about pairs where the student’s prediction on the original equals the label (others get"student incorrect!"); any other value asks about every swapped pair.
- Variables:
round (
int) – Index of the next feedback round; incremented on everyget_feedback()call, including calls that need no verdict.- Raises:
ValueError – If
auto_verdictis set to something other than the three verdicts.
Methods
Return one verdict per collage, asking the web app for the open ones.
Path of the request file the teacher writes for round
round_idx.Path of the response file the web app writes for round
round_idx.- __init__(feedback_dir, poll_interval=2.0, timeout_s=None, auto_verdict=None, min_confidence=0.5, tracking_level=0, counterfactual_type='1sided')[source]¶
Store the settings, resolve
auto_verdictand createfeedback_dir.
- get_feedback(collage_path_list, y_target_end_confidence_list, y_source_list, y_list, y_target_list=None, **kwargs)[source]¶
Return one verdict per collage, asking the web app for the open ones.
- Parameters:
collage_path_list (
listofstr) – Paths of the contrastive collages, one per counterfactual pair.y_target_end_confidence_list (
listoffloat) – Predictor confidence for the target class on each counterfactual.y_source_list (
listofint) – Student prediction on each original image.y_list (
listofint) – Ground-truth label of each original image.y_target_list (
listofint, optional) – Target class of each counterfactual; passed through to the request.**kwargs – Ignored; accepted for compatibility with other teachers.
- Returns:
Same length and order as
collage_path_list. Entries are"true","false"or"ood"for pairs a person (orauto_verdict) judged,"student incorrect!"when the student was wrong on the original (1-sided mode only) and"student not swapped!"when the end confidence is belowmin_confidence.- Return type:
Notes
Writes
feedback_request_<round>.jsonwith the items to judge and blocks in_wait_for_response()until the matching response file holds a valid verdict for every requested index. The round counter is advanced even when nothing has to be asked.