hired.alignment.calibration#
Calibrated confidence: multi-sample consistency and a conformal ask/auto-decide rule.
Self-reported confidence (an LLM saying “high”) is overconfident; the honesty
contract needs a signal that is not. Two deterministic pieces, the judgments
themselves staying external (the hired-align skill or an injected LLM):
Consistency. Ask the same question several times and see how often the answers agree in meaning (
semantic_consistency()). Agreement is the signal;match_share()turns sampled match states into a score in[0, 1]andconfidence_level()into aConfidenceLevel.Conformal abstention. On a held-out set of scored, labelled judgments,
calibrate_match()fits a class-conditional (Mondrian) split-conformalrule.
MatchCalibrator.decide()then auto-accepts a match only when the score excludes “no match” at levelfalse_accept_rate, auto-rejects only when it excludes “match” at levelmiss_rate, and otherwise says ask.
The guarantee: over calibration and test drawn alike (exchangeable), a true
non-match is auto-accepted with probability at most false_accept_rate, and a
true match auto-rejected with probability at most miss_rate. The asymmetry
(“never exaggerate”) is the choice of a smaller false_accept_rate. With too
few calibration examples of a class to support its level, the rule never
auto-decides against that class: it asks.
See misc/docs/research/jd-candidate-matching.md (unknown vs absent) and #12.
>>> scores = [0.9, 0.95, 0.8, 1.0, 0.85] * 8 + [0.1, 0.2, 0.0, 0.3, 0.15] * 8
>>> labels = [True] * 40 + [False] * 40
>>> cal = calibrate_match(scores, labels, false_accept_rate=0.05, miss_rate=0.1)
>>> cal.decide(0.97), cal.decide(0.05), cal.decide(0.5)
(<Decision.AUTO_MATCH: 'auto_match'>, <Decision.AUTO_NO_MATCH: 'auto_no_match'>, <Decision.ASK: 'ask'>)
Functions
|
Set |
|
Fit the ask/auto-decide rule on held-out judgments with known truth. |
|
The split-conformal threshold: the |
|
A |
|
The share of sampled judgments that say "match": a score in |
|
The agreement of sampled answers, clustered by |
Classes
|
How far several sampled answers to one question agree. |
|
What to do with a judgment: take it as a match, as no match, or ask. |
|
A fitted class-conditional conformal rule over a match score |
- class hired.alignment.calibration.Consistency(majority, agreement, entropy, n_samples, counts=dict())[source]#
Bases:
objectHow far several sampled answers to one question agree.
majorityis the most common meaning (Nonewithout samples),agreementits share,entropythe Shannon entropy of the meanings normalised to[0, 1](0: all agree; 1: spread evenly over the meanings found),countsthe number of samples per meaning.
- class hired.alignment.calibration.Decision(*values)[source]#
-
What to do with a judgment: take it as a match, as no match, or ask.
- class hired.alignment.calibration.MatchCalibrator(match_threshold, no_match_threshold, false_accept_rate=0.05, miss_rate=0.1, n_match=0, n_no_match=0)[source]#
Bases:
objectA fitted class-conditional conformal rule over a match score
sin[0, 1].“Match” stays in the prediction set while its nonconformity
1 - sis at mostmatch_threshold; “no match” whilesis at mostno_match_threshold. A singleton set decides; two labels (or none) mean ask. JSON-ready throughto_dict()/from_dict(), so a fitted rule can be stored and reviewed.
- hired.alignment.calibration.apply_calibration(record, samples, *, calibrator=None, meaning=None, is_match=None)[source]#
Set
record’s confidence from sampled judgments, and its decision if calibrated.samplesare several independent judgments of the same requirement (match states, by default). The record’sconfidencebecomesconfidence_level()of their agreement and itsmatch_scorematch_share(); with acalibrator,calibrated_decisionis itsdecide(), whichshould_ask()honours (without one it is cleared: new samples supersede an old decision, so re-apply, or clear it, once an answer settles the requirement). The match state stays the analyst’s: an ask questions a claim, it does not overturn it. Returns the record, changed in place.>>> from hired.alignment.base import Requirement >>> rec = RequirementRecord(requirement=Requirement(text="Kafka"), match_state="confirmed") >>> rec = apply_calibration(rec, ["confirmed", "confirmed", "unknown"]) >>> rec.confidence.value, round(rec.match_score, 2), rec.calibrated_decision ('medium', 0.67, None)
- Return type:
- hired.alignment.calibration.calibrate_match(scores, labels, *, false_accept_rate=0.05, miss_rate=0.1)[source]#
Fit the ask/auto-decide rule on held-out judgments with known truth.
scoresare match scores in[0, 1](saymatch_share()of sampled judgments),labelswhether each was truly a match. Each class gets its own threshold (Mondrian split conformal):false_accept_ratebounds how often a true non-match is auto-accepted,miss_ratehow often a true match is auto-rejected. Keep the held-out set apart from anything used to tune the scoring, or the bound does not hold.- Return type:
- hired.alignment.calibration.confidence_level(agreement, *, high=0.9, medium=0.6)[source]#
A
ConfidenceLevelfrom sampled agreement rather than self-report.>>> confidence_level(0.95), confidence_level(0.7), confidence_level(0.5) (<ConfidenceLevel.HIGH: 'high'>, <ConfidenceLevel.MEDIUM: 'medium'>, <ConfidenceLevel.LOW: 'low'>)
- Return type:
- hired.alignment.calibration.conformal_quantile(scores, alpha)[source]#
The split-conformal threshold: the
ceil((n+1)(1-alpha))-th smallest score.A new score drawn like these exceeds it with probability at most
alpha. Whennis too small foralpha(ceil((n+1)(1-alpha)) > n) no finite threshold has that guarantee, and this returnsinf.>>> conformal_quantile([0.1, 0.2, 0.3, 0.4], 0.2) # ceil(5 * 0.8) = 4th 0.4 >>> conformal_quantile([0.1, 0.2], 0.1) inf
- Return type:
The share of sampled judgments that say “match”: a score in
[0, 1].By default a sample matches when it is (or names)
MatchState.CONFIRMED;is_matchoverrides that. This is the scorecalibrate_match()takes.>>> match_share(["confirmed", "confirmed", "unknown", "contradicted"]) 0.5
- Return type:
- hired.alignment.calibration.semantic_consistency(samples, *, meaning=None)[source]#
The agreement of sampled answers, clustered by
meaning(default: equality).meaningmaps an answer to its meaning: a normalised label, an entailment cluster id. Answers that mean the same count as agreeing however worded.>>> c = semantic_consistency(["Yes", "yes", "no", "YES "], meaning=lambda s: s.strip().lower()) >>> c.majority, c.agreement, round(c.entropy, 3) ('yes', 0.75, 0.811) >>> semantic_consistency([]).agreement 0.0
- Return type: