recall_guard.harness.evaluator
recall_guard.harness.evaluator
Per-model evaluator: from raw eval set to ModelEvalResult with bootstrap CIs.
Implements the harness.evaluator component from the honest-model-ranking
design (see design.md → Components and Interfaces → harness.evaluator).
Satisfies Requirements 3.3, 4.3, 5.4, 6.1, 6.2, 6.3, 7.1, 7.2, 7.3, and 10.3.
Pipeline per eval row:
1. Call model_lm.generate(prompt). Map TimeoutError to
fail_reason="timeout" and RuntimeError to either
"no_logprobs" (message mentions logprobs / top_logprobs) or the
generic "error" bucket. Any other exception also falls into "error".
2. On success, optionally call ref_lm.generate(prompt) to obtain reference
logprobs. A reference-side failure does not invalidate the row; it merely
sets ref_logprobs=None.
3. Parse Direction: strictly (only -1, 0, 1) and Confidence: strictly
(must be a float in [0, 1]). Either parse failure → parse_ok=False,
fail_reason="parse_failure".
4. Compute MIA features, standardise against the per-model baseline, run
mcs.predict_proba to get p_memorized, and apply the continuous
penalty penalized_confidence = raw_confidence * (1 - p_memorized)
(Req 5.4: no thresholds).
Bootstrap CIs (Req 6.1, 6.3) are computed via core.bootstrap.bootstrap_ci
over parse-OK rows for accuracy and over (p_memorized, label) pairs from
the supplied holdout_records for MCS-AUC. When no holdout records are
available, the CI collapses to the calibrator's holdout_auc point estimate
(documented fallback in design.md → Implementation Notes).
The temperature-not-honoured warning (Req 10.3) is surfaced when any LM call
returns a non-None, non-zero raw_temperature_observed. All other warnings
(weak-calibration, parse-unreliable, not-better-than-baseline, uncalibrated)
are emitted by the ranker, not here.
Record
dataclass
Per-(model, prompt) record produced by evaluate_model.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
str
|
NVIDIA model ID this record was scored for. |
prompt_hash |
str
|
First 16 hex chars of |
parse_ok |
bool
|
|
predicted_direction |
int | None
|
Parsed integer in |
raw_confidence |
float | None
|
Parsed confidence in |
penalized_confidence |
float | None
|
|
target_direction |
int
|
Ground-truth direction copied from the eval row (always populated). |
features_raw |
MiaFeatures | None
|
:class: |
features_standardised |
dict[str, float | None] | None
|
Per-feature standardised values (z-score against the model's baseline);
|
p_memorized |
float | None
|
|
fail_reason |
str | None
|
One of |
raw_response_excerpt |
str | None
|
First ~400 chars of the raw model response when the row failed to
parse. Always |
Source code in recall_guard/harness/evaluator.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
CIBound
dataclass
A bootstrap point estimate plus 95% percentile bounds.
Source code in recall_guard/harness/evaluator.py
174 175 176 177 178 179 180 | |
ModelEvalResult
dataclass
Aggregate evaluation result for one model on the eval set.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
str
|
NVIDIA model ID. |
raw_accuracy |
CIBound
|
Bootstrap CI on |
memguard_accuracy |
CIBound
|
Same accuracy denominator as |
mcs_auc |
CIBound
|
Bootstrap CI over the |
parse_success_rate |
float
|
Fraction of rows with |
parse_failures |
int
|
Count of rows with |
warnings |
list[str]
|
Subset of |
records |
list[Record]
|
Per-row records in eval-set order. |
Source code in recall_guard/harness/evaluator.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
evaluate_model
evaluate_model(
model_lm,
eval_set,
baseline,
mcs,
ref_lm,
holdout_records=None,
bootstrap_n=1000,
seed=0,
max_workers=1,
)
Score one model against eval_set and assemble a ModelEvalResult.
With max_workers > 1 the per-row primary + reference LM calls
fan out via concurrent.futures.ThreadPoolExecutor (results are
paired with rows by index, so order is preserved). Post-processing
(parsing, MIA feature compute, MCS scoring) runs serially.
See module docstring for the row-level pipeline. The function performs no
I/O beyond the model HTTP calls; all artifact writing is owned by
harness.report and harness.runner.
Source code in recall_guard/harness/evaluator.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
compute_majority_baseline
compute_majority_baseline(
eval_set, bootstrap_n=1000, seed=0
)
Bootstrap CI on the majority-class baseline accuracy (Req 6.2).
Returns CIBound(0.0, 0.0, 0.0) for an empty eval set.
Source code in recall_guard/harness/evaluator.py
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |