hired.alignment.calibration_log#

Collect held-out (score, truth) pairs from answered clarifications and fit a calibrator.

calibrate_match() needs scored judgments with known truth. The truth arrives when the candidate answers a clarifying question (record_qa()): the record’s match_score before the answer, plus what the answer established. CalibrationLog appends each pair to the user’s info/calibration/pairs.jsonl and, once both classes have enough pairs for the chosen levels, fits and persists a MatchCalibrator (info/calibration/calibrator.json) that the hired-align workflow loads with CalibrationLog.load_calibrator().

Keep these pairs out of anything used to tune the scoring: the conformal bound only holds for data the scorer never saw.

>>> import tempfile
>>> from hired.persistence.base import UserStore
>>> log = CalibrationLog(UserStore("t", root=tempfile.mkdtemp()))
>>> log.add(0.9, True, qa_id="qa-1")
>>> log.pairs()
[(0.9, True)]
>>> log.fit() is None  # too few pairs for the default levels
True

Functions

min_pairs(rate)

Pairs a class needs for a finite threshold at rate: ceil(1/rate) - 1.

Classes

CalibrationLog([store, false_accept_rate, ...])

The user's calibration pairs and fitted calibrator, kept under info/calibration/.

class hired.alignment.calibration_log.CalibrationLog(store=None, *, false_accept_rate=0.05, miss_rate=0.1)[source]#

Bases: object

The user’s calibration pairs and fitted calibrator, kept under info/calibration/.

add(match_score, truth, *, qa_id=None)[source]#

Append one pair (the score before the answer, the truth the answer established).

Return type:

None

add_and_refit(match_score, truth, *, qa_id=None)[source]#

add() a pair, then refit and persist when ready; return the calibrator.

Return type:

MatchCalibrator | None

fit(*, persist=False)[source]#

Fit on the logged pairs; None until ready(). persist saves the result.

Return type:

MatchCalibrator | None

load_calibrator()[source]#

The persisted calibrator, or None if none has been fitted yet.

Return type:

MatchCalibrator | None

ready()[source]#

Whether each class has enough pairs for its level.

Return type:

bool

hired.alignment.calibration_log.min_pairs(rate)[source]#

Pairs a class needs for a finite threshold at rate: ceil(1/rate) - 1.

>>> min_pairs(0.05), min_pairs(0.1)
(19, 9)
Return type:

int