typedecide.evaluation.runner¶
evaluate, evaluate_with_scorer, EvalResult and the debiasing modes. Task-oriented walkthrough: Evaluate like a sceptic.
typedecide.evaluation.runner
¶
Running an evaluation, and reporting it the way a sceptic would read it.
The failure this module exists to catch is a model that answers by option position rather than by reading the evidence. On a balanced set that model scores chance, and "chance" in an accuracy column looks like a weak model rather than a broken one. So three numbers are reported together and none of them is optional:
balanced accuracy is it right, with every class weighted equally order consistency does the answer survive reordering the options letter distribution which letters did it actually pick
debias goes further than reporting. Scoring a decision under several orderings and
averaging the probability assigned to each option id cancels a position prior
exactly: under a cyclic or full permutation set every option spends the same time in
every slot, so whatever bonus the slot carries is added to every option equally and
falls out of the argmax. That repairs the readout. It does not repair the model --
order consistency and the letter histogram will still show the prior, which is why
they are reported even when debiasing is on.
EvalResult
dataclass
¶
EvalResult(
accuracy: float,
balanced_accuracy: float,
order_consistency: float | None,
ece: float | None,
brier: float | None,
per_criterion: dict[str, float],
letter_distribution: dict[str, float],
n: int,
manifest: dict[str, Any] = dict(),
)
One evaluation, with everything needed to argue about it.
manifest
class-attribute
instance-attribute
¶
render
¶
A short human-readable block, for the CLI and for pasting into a log.
Source code in src/typedecide/evaluation/runner.py
orderings
¶
The option orderings to score for one decision under a debiasing mode.
"none" scores the options as given. "cyclic" and "calibrated" score the n rotations. "permutation" scores all n! arrangements. Every mode but "none" puts each option in each position the same number of times, which is what makes the position prior cancel under averaging.
Source code in src/typedecide/evaluation/runner.py
evaluate_with_scorer
¶
evaluate_with_scorer(
decisions: Sequence[Decision],
score: ScoreFn,
*,
debias: str = "none",
seed: int = 0,
manifest: dict[str, Any] | None = None
) -> EvalResult
Score decisions with an injected ScoreFn.
evaluate is this function with a model attached. Keeping the scorer injectable
is not only for tests: it is also how you score an ONNX export, a remote endpoint
or a cached set of logits without reimplementing the debiasing.
Source code in src/typedecide/evaluation/runner.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
evaluate
¶
evaluate(
decisions: Sequence[Decision],
model_id: str,
*,
adapter: Path | None = None,
debias: str = "none",
batch_size: int = 8,
device: str | None = None,
seed: int = 0
) -> EvalResult
Load a model and score decisions with it.
debias selects how many orderings each decision is scored under; see
orderings. Requires the train extra (torch, transformers, and peft if an
adapter is given).