Calibration and bands¶
Guides: calibration and escalation.
calibrate ¶
calibrate(
model,
examples: Sequence[Tuple],
questions: Mapping,
alpha: float = 0.1,
min_examples: int = 10,
views: int = 1,
readout: str = "engine",
target_precision: float = None,
review_rate: float = None,
max_review_rate: float = 1.0,
band_confidence: float = 0.95,
band_default: float = None,
frontier: bool = False,
) -> Calibration
Fit a :class:Calibration from labelled examples, one engine read per example.
examples has :meth:Vega.fit's shape: (state, {question_id: label}), with an
optional third element carrying per-example questions. alpha is the miscoverage the
conformal sets should hold on data like these examples.
target_precision also fits the escalation band: the confidence line below which an answer
goes to a human, chosen as the widest automatic band whose precision holds at that target with
band_confidence to spare, and capped by max_review_rate when a pilot has only so many
reviewers. review_rate instead fixes the share sent to review and reports the precision
that buys. band_default covers questions that got no band of their own. One of the two
targets, not both.
Calibration ¶
Calibration(
alpha: float,
questions: Dict[str, Dict],
report: Dict[str, Dict],
band=None,
reference: Dict[str, Dict] = None,
provenance: Dict = None,
)
Per-question temperature, conformal threshold and review band, fitted by :func:calibrate.
report says, per question, what was fitted and what it changed, including the in-sample
ECE before and after. Questions with too few examples are left exactly as the engine
answered them, and the report names them.
band is the escalation policy, present when :func:calibrate was given a
target_precision or a review_rate; :meth:apply then routes every answer to "auto" or
"review". reference records, per question, the answer mix and mean confidence these
examples produced, which is what :mod:vegaml.monitor compares your live traffic against.
checksum ¶
sha256 of everything that changes an answer: alpha, the per-question fit, the band.
Not the report, not the reference mix and not the provenance, because those describe the fit without taking part in it: two calibrations that round-trip to the same numbers should have the same checksum whatever got written alongside them. A deployment records this next to every decision, which is what lets a decision from last March be re-run and defended.
version ¶
The short form of :meth:checksum, for a column and for a human to read aloud.
apply ¶
A copy of a decide() result with every calibrated question's answer corrected.
to_payload ¶
The whole calibration as plain JSON-able data, stamped with its own version.
Separate from :meth:save because a deployment that keeps calibrations in a database
column should not have to go via a temporary file to do it.
mismatches ¶
Why this calibration does not belong to model, as plain sentences, or an empty list.
A temperature and a threshold are fitted for one engine behind one reader. Applied to another they are arithmetic without meaning, and nothing in the numbers themselves says so, which is exactly the kind of error that survives into production.
Band ¶
Band(
questions: Optional[Mapping[str, Mapping]] = None,
default: Optional[float] = None,
report: Optional[Mapping] = None,
)
A review line per question: below it the answer is a human's, above it the machine's.
questions maps a question id to the dict :func:fit_threshold returns, or to anything
carrying a threshold. default covers questions with no line of their own; without one
they come back route="unbanded", so a question nobody configured is never silently
auto-approved on a policy it was not measured under.