Evaluation¶
Every report holds counts and identifiers only, never document, question or answer text. Published numbers and what they do and do not show are on the Benchmarks page; the evaluation guide is here.
De-identification¶
openbtk.eval.deid.evaluate_deid ¶
evaluate_deid(engine: DeidEngine, documents: Iterable[_DocumentLike]) -> EvaluationResult
Run engine over documents and score it against their
ground-truth spans.
documents is consumed once (streaming, ADR-0004): a full n2c2 corpus
is never held in memory. A document's optional unscored_spans count
(see openbtk.deid.labelled.LabelledDocument) is summed into the
result so a report states how much annotation it did not score.
Source code in src/openbtk/eval/deid.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 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 | |
openbtk.eval.deid.EvaluationResult ¶
Bases: BaseModel
Scores for one benchmark run. Counts and category names only.
openbtk.eval.deid.CategoryMetrics ¶
Bases: BaseModel
True/false positive and false-negative counts, with derived scores.
An undefined ratio (no predictions, or no ground truth) is reported as
1.0 -- "nothing to get wrong" -- matching M2's accuracy gate; consult
true_positives/false_negatives to tell "perfect" from "vacuous".
Example
m = CategoryMetrics(true_positives=3, false_positives=1, false_negatives=1) m.precision, m.recall (0.75, 0.75)
openbtk.eval.deid.report_dict ¶
report_dict(result: EvaluationResult) -> dict[str, object]
A JSON-serialisable report including the derived precision/recall/F1
(Pydantic properties are not part of model_dump). Counts and category
names only -- safe to share.
Source code in src/openbtk/eval/deid.py
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 | |
openbtk.eval.deid.format_markdown ¶
format_markdown(result: EvaluationResult, *, title: str = 'De-identification') -> str
Render result as a Markdown report: counts and scores only, never
any document text.
Source code in src/openbtk/eval/deid.py
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 | |
openbtk.deid.labelled.LabelledDocument ¶
Bases: BaseModel
A document plus its ground-truth PHI annotations.
unscored_spans counts annotations in the source dataset that have no
Safe Harbor PHICategory equivalent (e.g. i2b2's PROFESSION or AGE
tags) and were therefore left out of spans -- carried as a count, not
dropped silently, so a benchmark report can state exactly how much of the
dataset's annotation it did not score.
Example
doc = LabelledDocument(document_id="d1", text="x", spans=[]) doc.unscored_spans 0
openbtk.deid.labelled.LabelledSpan ¶
Bases: BaseModel
One annotated PHI span: category plus half-open [start, end) offsets.
Example
LabelledSpan(category=PHICategory.SSN, start=4, end=15).end 15
openbtk.data.clinical_text.datasets.N2C2DeidDataset ¶
N2C2DeidDataset(*, path: str | None = None)
Bases: BaseDatasetAdapter
i2b2/n2c2 2014 de-identification corpus, from a user-supplied directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | None
|
Directory of |
None
|
Example
import contextlib, io, tempfile from pathlib import Path xml = ( ... '
' ... ) with tempfile.TemporaryDirectory() as d: ... _ = (Path(d) / "doc1.xml").write_text(xml) ... with contextlib.redirect_stdout(io.StringIO()): ... docs = list(N2C2DeidDataset(path=d).load()) docs[0].spans[0].category.value 'date' ' ... '
Source code in src/openbtk/data/clinical_text/datasets.py
112 113 | |
load ¶
load(**kwargs: Any) -> Iterator[LabelledDocument]
Validate the source now, then stream documents lazily.
Raises:
| Type | Description |
|---|---|
DatasetError
|
If no directory was supplied or it does not exist (the message names the registration page -- this class never downloads), or, while iterating, if a file is malformed or its tag offsets do not match its text. |
Source code in src/openbtk/data/clinical_text/datasets.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
Retrieval¶
openbtk.eval.retrieval.evaluate_retrieval ¶
evaluate_retrieval(retrieve: Callable[[str], Sequence[str]], queries: Iterable[RetrievalQuery], *, ks: Sequence[int] = DEFAULT_KS) -> RetrievalReport
Score retrieve (query text -> ranked document ids) over queries.
queries is consumed once (streaming); memory does not grow with the
number of queries.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
qs = [RetrievalQuery(query_id="q", query="x", relevance={"a": 1.0})] report = evaluate_retrieval(lambda text: ["a", "b"], qs, ks=(1,)) report.mrr, report.recall_at_k[1] (1.0, 1.0)
Source code in src/openbtk/eval/retrieval.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
openbtk.eval.retrieval.retriever_from ¶
retriever_from(embedding: BaseEmbeddingProvider, vectorstore: BaseVectorStore, *, top_k: int = 10, id_of: Callable[[SearchResult], str] | None = None) -> Callable[[str], list[str]]
Build a query -> ranked ids callable from a real embedding
provider and vector store, so the same metrics score whatever retrieval
stack a user actually runs. id_of defaults to the hit's own id; pass
e.g. lambda r: r.source.record_id to judge at record rather than
chunk level.
Source code in src/openbtk/eval/retrieval.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
openbtk.eval.retrieval.RetrievalQuery ¶
Bases: BaseModel
One evaluation query with its graded relevance judgements.
Example
q = RetrievalQuery(query_id="q1", query="diabetes", relevance={"c3": 1.0}) q.relevant_ids ['c3']
openbtk.eval.retrieval.RetrievalReport ¶
Bases: BaseModel
Macro-averaged metrics over every evaluated query.
openbtk.eval.retrieval.recall_at_k ¶
recall_at_k(ranked_ids: Sequence[str], relevant: Iterable[str], k: int) -> float
Fraction of the relevant documents found in the top k.
Example
recall_at_k(["a", "b", "c"], {"a", "z"}, k=2) 0.5
Source code in src/openbtk/eval/retrieval.py
60 61 62 63 64 65 66 67 68 69 70 71 72 | |
openbtk.eval.retrieval.reciprocal_rank ¶
reciprocal_rank(ranked_ids: Sequence[str], relevant: Iterable[str]) -> float
1 / rank of the first relevant result, or 0.0 if none was retrieved.
Example
reciprocal_rank(["x", "a", "b"], {"a"}) 0.5
Source code in src/openbtk/eval/retrieval.py
75 76 77 78 79 80 81 82 83 84 85 86 | |
openbtk.eval.retrieval.ndcg_at_k ¶
ndcg_at_k(ranked_ids: Sequence[str], relevance: Mapping[str, float], k: int) -> float
Normalised discounted cumulative gain at k (linear gain).
Example
ndcg_at_k(["a", "b"], {"a": 1.0, "b": 1.0}, k=2) 1.0 round(ndcg_at_k(["x", "a"], {"a": 1.0}, k=2), 4) 0.6309
Source code in src/openbtk/eval/retrieval.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
Clinical QA¶
openbtk.eval.qa.evaluate_qa ¶
evaluate_qa(answerer: Callable[[str], str], items: Iterable[MCQItem], *, keep_results: bool = False) -> QAReport
Score answerer -- a function from a prompt to a reply -- on items.
items is consumed once and never materialised, so a full MedMCQA
training split streams in constant memory. An exception from answerer
(a provider outage, say) propagates: a QA score silently computed over the
questions that happened to succeed would be a wrong number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
answerer
|
Callable[[str], str]
|
|
required |
items
|
Iterable[MCQItem]
|
Questions to ask. |
required |
keep_results
|
bool
|
Also record each question's id, chosen letter and correctness (ids and letters only). |
False
|
Source code in src/openbtk/eval/qa.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
openbtk.eval.qa.LLMAnswerer ¶
LLMAnswerer(provider: BaseLLMProvider, **generation: Any)
Adapt a BaseLLMProvider to evaluate_qa's prompt -> reply,
accumulating its token usage across the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
BaseLLMProvider
|
The model under test. |
required |
**generation
|
Any
|
Passed to |
{}
|
Source code in src/openbtk/eval/qa.py
401 402 403 404 | |
openbtk.eval.qa.QAReport ¶
Bases: BaseModel
Scores for one QA run. Counts and ids only.
Unanswered questions (no parsable option) count as wrong and are also reported separately, so a model that rambles is visible rather than merely scoring low.
accuracy_ci95
property
¶
accuracy_ci95: tuple[float, float]
95% Wilson score interval for accuracy: how much a score of this
size can move by chance alone. (0.0, 1.0) for an empty run.
as_dict ¶
as_dict() -> dict[str, JsonValue]
A JSON-serialisable summary (no per-item results), counts only.
Source code in src/openbtk/eval/qa.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
openbtk.eval.qa.MCQItem ¶
Bases: BaseModel
One multiple-choice question.
Example
item = MCQItem( ... item_id="q1", ... question="Which vitamin deficiency causes scurvy?", ... options={"A": "Vitamin A", "B": "Vitamin C"}, ... answer="B", ... ) item.options[item.answer] 'Vitamin C'
openbtk.eval.qa.read_medqa_jsonl ¶
read_medqa_jsonl(path: str | Path) -> Iterator[MCQItem]
Stream MedQA-format questions from a JSON Lines file.
Raises:
| Type | Description |
|---|---|
DatasetError
|
On unreadable or malformed input, or a question whose correct option cannot be determined. The message names the line, never the question. |
Source code in src/openbtk/eval/qa.py
112 113 114 115 116 117 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 | |
openbtk.eval.qa.read_medmcqa_jsonl ¶
read_medmcqa_jsonl(path: str | Path) -> Iterator[MCQItem]
Stream MedMCQA-format questions from a JSON Lines file.
Raises:
| Type | Description |
|---|---|
DatasetError
|
On unreadable or malformed input, a hidden answer key, or
an ambiguous |
Source code in src/openbtk/eval/qa.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
openbtk.eval.qa.parse_choice ¶
parse_choice(text: str, letters: Iterable[str]) -> str | None
Extract the chosen option letter from a model's free-text reply.
Recognises "B", "(B)", "B. text", "B) text" and
"...the answer is B" / "Answer: B". It does not accept a bare
letter buried in prose ("A patient with ..." starts with the article
"A"), so an evasive or rambling reply is counted as unanswered instead of
being credited by accident. Returns None when no option can be
identified, or when the letter is not one of letters.
Example
parse_choice("The answer is C.", "ABCD") 'C' parse_choice("(b) Vitamin C", "ABCD") 'B' parse_choice("A patient presents with fever.", "ABCD") is None True
Source code in src/openbtk/eval/qa.py
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 | |
openbtk.eval.qa.format_prompt ¶
format_prompt(item: MCQItem) -> str
The zero-shot prompt this module sends for item.
Example
item = MCQItem( ... item_id="q", question="Q?", options={"A": "x", "B": "y"}, answer="A" ... ) prompt = format_prompt(item) "A. x" in prompt and prompt.endswith("Answer:") True
Source code in src/openbtk/eval/qa.py
207 208 209 210 211 212 213 214 215 216 217 218 219 | |
openbtk.eval.qa.qa_manifest ¶
qa_manifest(report: QAReport, *, component: ComponentProvenance | None = None, source: str | Path | None = None) -> EvalManifest
The provenance record for a QA run (FR-X-06): which model, which file (by SHA-256), when, and the counts -- no question or answer text.
Source code in src/openbtk/eval/qa.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
Groundedness¶
openbtk.eval.groundedness.score_groundedness ¶
score_groundedness(examples: Iterable[GroundedExample], guardrail: GroundednessGuardrail | None = None) -> GroundednessReport
Score how faithful a set of generated answers is to their contexts.
examples is consumed once. guardrail defaults to the word-overlap
heuristic (see the module docstring for what that can and cannot see).
Example
ok = GroundedExample( ... example_id="a", ... answer="The patient has type 2 diabetes.", ... context=["Assessment: type 2 diabetes mellitus, stable."], ... ) bad = GroundedExample( ... example_id="b", ... answer="The patient has a fractured femur.", ... context=["Assessment: type 2 diabetes mellitus, stable."], ... ) report = score_groundedness([ok, bad]) report.faithfulness, report.fully_grounded_examples (0.5, 1)
Source code in src/openbtk/eval/groundedness.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 | |
openbtk.eval.groundedness.evaluate_detector ¶
evaluate_detector(examples: Iterable[LabelledExample], guardrail: GroundednessGuardrail | None = None) -> DetectorReport
Measure how well guardrail separates grounded from ungrounded answers
against human labels.
Example
good = LabelledExample( ... example_id="a", grounded=True, ... answer="The patient has type 2 diabetes.", ... context=["Assessment: type 2 diabetes mellitus, stable."], ... ) bad = LabelledExample( ... example_id="b", grounded=False, ... answer="The patient has a fractured femur.", ... context=["Assessment: type 2 diabetes mellitus, stable."], ... ) evaluate_detector([good, bad]).f1 1.0
Source code in src/openbtk/eval/groundedness.py
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 225 226 227 228 229 230 231 232 | |
openbtk.eval.groundedness.GroundedExample ¶
Bases: BaseModel
An answer and the source text it should be grounded in.
openbtk.eval.groundedness.LabelledExample ¶
Bases: GroundedExample
A :class:GroundedExample a human judged: grounded is True when every
claim in answer is supported by context.
openbtk.eval.groundedness.GroundednessReport ¶
Bases: BaseModel
Claim-level faithfulness over a set of examples. Counts only.
openbtk.eval.groundedness.DetectorReport ¶
Bases: BaseModel
Agreement between the checker and human labels, for the task of detecting ungrounded answers (the positive class is "not grounded").
openbtk.eval.groundedness.groundedness_manifest ¶
groundedness_manifest(report: GroundednessReport) -> EvalManifest
The provenance record for a groundedness run (FR-X-06): when, and the counts -- no answer or context text.
Source code in src/openbtk/eval/groundedness.py
235 236 237 238 239 240 241 242 243 | |
Summaries: ROUGE and BERTScore¶
openbtk.eval.summarisation.evaluate_summaries ¶
evaluate_summaries(pairs: Iterable[SummaryPair], *, rouge_types: Sequence[str] = ROUGE_TYPES, use_stemmer: bool = True, bertscorer: BertScorer | None = None) -> SummarisationReport
Score candidate summaries against references.
Streams the pairs, holding only the running sums and one small record of scores per example. The report's means are macro averages: every example counts once, however long its summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pairs
|
Iterable[SummaryPair]
|
The candidate and reference of each example. |
required |
rouge_types
|
Sequence[str]
|
ROUGE variants to compute ( |
ROUGE_TYPES
|
use_stemmer
|
bool
|
Stem before ROUGE matching. |
True
|
bertscorer
|
BertScorer | None
|
Also compute BERTScore with this scorer ( |
None
|
Example
report = evaluate_summaries( ... [SummaryPair(example_id="a", reference="stable", candidate="stable")] ... ) report.rouge["rouge1"].f1, report.n (1.0, 1)
Source code in src/openbtk/eval/summarisation.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
openbtk.eval.summarisation.rouge_scores ¶
rouge_scores(reference: str, candidate: str, *, types: Sequence[str] = ROUGE_TYPES, use_stemmer: bool = True) -> dict[str, Prf]
ROUGE precision, recall and F1 of one candidate against one reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
str
|
The reference summary. |
required |
candidate
|
str
|
The candidate summary. |
required |
types
|
Sequence[str]
|
Which variants: |
ROUGE_TYPES
|
use_stemmer
|
bool
|
Porter-stem words first (the usual reporting convention). |
True
|
Raises:
| Type | Description |
|---|---|
ConfigError
|
On an unknown variant. |
MissingDependencyError
|
If |
Example
scores = rouge_scores("the patient is stable", "the patient is stable") scores["rouge1"].f1 1.0
Source code in src/openbtk/eval/summarisation.py
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 172 | |
openbtk.eval.summarisation.BertScorer ¶
BertScorer(*, model: str, revision: str, layer: int, device: str = 'cpu', max_length: int = 512)
BERTScore with a model, revision and layer you choose. See the module docstring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
A Hugging Face Hub encoder id (or local path). |
required |
revision
|
str
|
The pinned commit of |
required |
layer
|
int
|
Which hidden layer's token embeddings to compare, |
required |
device
|
str
|
A torch device string. |
'cpu'
|
max_length
|
int
|
Tokens kept per text; a longer text is truncated, and the score covers only what was kept. |
512
|
Example
scorer = BertScorer(model="org/encoder", revision="abc1234", layer=8) scorer.provenance().model_identity.revision # nothing is loaded yet 'abc1234'
Source code in src/openbtk/eval/summarisation.py
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 | |
provenance ¶
provenance() -> ComponentProvenance
The model, revision and layer, for a manifest.
Source code in src/openbtk/eval/summarisation.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
score ¶
score(reference: str, candidate: str) -> Prf
Raw BERTScore precision, recall and F1 of candidate vs reference.
As in the reference implementation, the special tokens ([CLS], [SEP])
carry zero weight in the averages but still take part in the matching, so a
token can be matched to the other text's special token. An empty (or
all-special-token) text scores 0 on all three.
Raises:
| Type | Description |
|---|---|
ProcessingError
|
If the model fails. The message never contains the text. |
Source code in src/openbtk/eval/summarisation.py
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 | |
openbtk.eval.summarisation.SummaryPair ¶
Bases: BaseModel
One candidate summary and the reference it is compared with.
Example
SummaryPair( ... example_id="d1", reference="Stable on discharge.", candidate="Stable." ... ).example_id 'd1'
openbtk.eval.summarisation.SummarisationReport ¶
Bases: BaseModel
Mean scores over the examples (a macro average) and each example's own.
Example
report = evaluate_summaries([], rouge_types=()) report.n 0
as_dict ¶
as_dict() -> dict[str, JsonValue]
A flat {name: number} view (rouge1_f1, bertscore_f1, n, ...),
the shape EvalManifest.report and ModelCard.with_evaluation read.
Source code in src/openbtk/eval/summarisation.py
112 113 114 115 116 117 118 119 120 121 122 123 124 | |
openbtk.eval.summarisation.summarisation_manifest ¶
summarisation_manifest(report: SummarisationReport, *, bertscorer: BertScorer | None = None, input_digests: Sequence[DataDigest] = ()) -> EvalManifest
The provenance record for a summarisation run: when, the mean scores and counts, the BERTScore model and revision if one was used, and the digests of the input files. Never the summaries.
Source code in src/openbtk/eval/summarisation.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
Model cards¶
openbtk.eval.model_card.ModelCard ¶
Bases: BaseModel
A model card. Build one with :meth:for_component or :func:cards_from_run.
Example
from openbtk.core.provenance import ModelIdentity card = ModelCard( ... model=ModelIdentity( ... name="org/model", revision="abc1234", source="huggingface" ... ), ... intended_use="Ranking passages for clinical question answering.", ... ) "## Intended use" in card.to_markdown() True "Not provided." in card.to_markdown() # the sections you did not write True
for_component
classmethod
¶
for_component(component: Component | ComponentProvenance, *, description: str | None = None, intended_use: str | None = None, out_of_scope_use: str | None = None, training_data: str | None = None, limitations: str | None = None, ethical_considerations: str | None = None, contact: str | None = None) -> ModelCard
A card for the model a component wraps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
Component | ComponentProvenance
|
A component instance or its provenance. It must carry a model identity (an LLM, an embedding provider, a cross-encoder reranker, ...). |
required |
description
|
str | None
|
One or two sentences on what the model is. |
None
|
intended_use
|
str | None
|
What it is meant for. |
None
|
out_of_scope_use
|
str | None
|
What it must not be used for. |
None
|
training_data
|
str | None
|
What it was trained on (for a fine-tune, what you trained it on). Openbtk cannot know this and does not guess. |
None
|
limitations
|
str | None
|
Known failure modes and blind spots. |
None
|
ethical_considerations
|
str | None
|
Risks, populations affected, mitigations. |
None
|
contact
|
str | None
|
Who to ask. |
None
|
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the component has no model identity (it wraps no model). |
Source code in src/openbtk/eval/model_card.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 | |
to_markdown ¶
to_markdown() -> str
The card as Markdown. Sections you did not provide say so.
Source code in src/openbtk/eval/model_card.py
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 | |
with_evaluation ¶
with_evaluation(manifest: EvalManifest, metric: str, *, name: str | None = None) -> ModelCard
A copy of this card with one score from an evaluation run attached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
EvalManifest
|
The |
required |
metric
|
str
|
The key of the score in |
required |
name
|
str | None
|
How to label it on the card (default: |
None
|
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the report has no numeric value under |
Source code in src/openbtk/eval/model_card.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
write ¶
write(path: str | Path) -> Path
Write the Markdown card to path (creating parent directories).
Source code in src/openbtk/eval/model_card.py
240 241 242 243 244 245 | |
openbtk.eval.model_card.CardEvaluation ¶
Bases: BaseModel
One metric on a card, with the evaluation run it came from.
openbtk.eval.model_card.cards_from_run ¶
cards_from_run(manifest: RunManifest, **text: str | None) -> list[ModelCard]
One card per distinct model a run used, read from its manifest.
Every step whose component recorded a model identity contributes a card; a model
used by several steps appears once. Any keyword (intended_use=...,
limitations=...) is applied to every card, so pass only what is true of all of
them, and write the rest with :meth:ModelCard.for_component.
Source code in src/openbtk/eval/model_card.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
Manifests¶
openbtk.eval.manifest.EvalManifest ¶
Bases: BaseModel
The audit record of one evaluation run.
Example
m = EvalManifest( ... eval_id="e1", kind="qa", started_at=datetime(2026, 1, 1, tzinfo=UTC), ... ended_at=datetime(2026, 1, 1, tzinfo=UTC), report={"n": 3}, ... ) m.manifest_version '1.0.0'
openbtk.eval.manifest.build_manifest ¶
build_manifest(kind: str, report: dict[str, JsonValue], *, started_at: datetime, ended_at: datetime | None = None, component: ComponentProvenance | None = None, input_digests: Sequence[DataDigest] = ()) -> EvalManifest
Assemble a manifest with a fresh id. ended_at defaults to now.
Source code in src/openbtk/eval/manifest.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
openbtk.eval.manifest.file_digest ¶
file_digest(path: str | Path, *, record_count: int) -> DataDigest
A DataDigest for a local file, hashed in 1 MiB chunks (so an
evaluation set is never held in memory just to be fingerprinted).
Example
import tempfile, pathlib with tempfile.TemporaryDirectory() as d: ... p = pathlib.Path(d) / "x.jsonl" ... _ = p.write_text("{}") ... digest = file_digest(p, record_count=1) len(digest.sha256 or "") 64
Source code in src/openbtk/eval/manifest.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |