typedecide.evaluation.readout¶
The ScoreFn seam and the torch-backed readout. Background: The typed logit readout.
typedecide.evaluation.readout
¶
Turning a causal language model into a probability distribution over options.
The readout is the whole trick of this library: instead of asking the model to write an answer and then parsing whatever it wrote, we build the prompt so that the very next token must be an answer letter, run one forward pass, and read the softmax over just those letters' logits. The output is a real distribution over the options that were listed, so it can be averaged over orderings and calibrated -- neither of which is possible with generated text.
Everything that touches torch or transformers is imported inside the function that
needs it, so import typedecide stays cheap and the base install stays light.
The seam that matters for testing is ScoreFn: anything that maps a batch of
ScoreRequest to a batch of probability vectors is a scorer. runner.evaluate
builds a TorchReadout; a test injects a fake and exercises the same debiasing code
with no model at all.
ScoreRequest
dataclass
¶
ScoreRequest(state: str, criterion: Criterion)
One prompt to score: a state, and a criterion in the exact option order to present. The returned probabilities are indexed by position in this criterion, so a caller that reordered the options must map them back to option ids itself.
TorchReadout
¶
TorchReadout(
model_id: str,
*,
adapter: Path | None = None,
device: str | None = None,
batch_size: int = 8,
seed: int = 0,
max_length: int | None = None
)
A ScoreFn backed by a local transformers model.
Construction loads the weights, so build one and reuse it across a whole eval rather than per decision.
Source code in src/typedecide/evaluation/readout.py
score
¶
score(
requests: Sequence[ScoreRequest],
) -> list[list[float]]
Probability over each request's options, in the order the request lists them.
Source code in src/typedecide/evaluation/readout.py
load_readout
¶
load_readout(
model_id: str,
*,
adapter: Path | None = None,
device: str | None = None,
batch_size: int = 8,
seed: int = 0,
max_length: int | None = None
) -> TorchReadout
Load a model and return it as a ScoreFn.