import tempfile
import jammi
from jammi_cookbook import fixtures
MODEL = fixtures.model("tiny_modernbert_classifier")
db = jammi.connect(f"file://{tempfile.mkdtemp()}")21 Evaluate inference (classification)
Run a classifier over a registered source and score its predictions against gold labels.
When to use this pattern. You have a labelled holdout set and you want a single number — accuracy, macro F1, per-class F1 — to compare two classifiers, or to track drift over time on the same classifier.
21.1 API surface exercised
Session.eval_inference(*, model, source, columns, task, golden_source, label_column)
The returned dict carries aggregate (tagged by "task" — currently "classification") with accuracy, f1, and per_class, plus per_record (one entry per aligned {record_id, predicted, gold}).
The task argument is the string form of the inference task — "classification" here. For NER, see ../eval_inference_ner/.
21.2 Golden source shape
eval_inference requires a registered source with these columns:
| column | type | example |
|---|---|---|
id |
utf8 | "1" |
<label_column> |
utf8 | physics |
label_column is the kwarg you pass at call time — label in this recipe. Every id in the golden source must resolve to a row in the input source; rows without a gold label are silently dropped from the metric.
The program is cookbook/recipes/eval_inference/example.py; its steps run here in order.
21.3 Register the corpus and the gold labels
The gold source is one (id, label) row per labelled corpus row.
db.add_source("corpus", url=str(fixtures.path("tiny_corpus.parquet")), format="parquet")
db.add_source("golden", url=str(fixtures.path("tiny_labels.csv")), format="csv")21.4 Run the classifier and score it
eval_inference runs the model over columns, aligns each prediction with its gold label by id, and returns the scores: aggregate holds accuracy and macro F1 (F1 averaged over the classes), tagged with the task.
metrics = db.eval_inference(
model=MODEL,
source="corpus",
columns=["content"],
task="classification",
golden_source="golden.public.tiny_labels",
label_column="label",
)
aggregate = metrics["aggregate"]
assert aggregate["task"] == "classification", aggregate["task"]
for key in ("accuracy", "f1"):
assert 0.0 <= aggregate[key] <= 1.0, f"{key} out of range: {aggregate[key]}"
print(f"accuracy: {aggregate['accuracy']:.4f}")
print(f"macro_f1: {aggregate['f1']:.4f}")accuracy: 0.4000
macro_f1: 0.2857
2026-10-03T07:44:50.595733Z WARN jammi_kernels::admission: fused-kernel domain check failed; falling back to the eager composition op="attention_block_fused" predicate="head_dim_is_attention_block_fixed_head_dim"
21.5 Read the breakdowns
aggregate["per_class"] scores each label on its own; per_record holds one aligned prediction and gold label per row.
per_class = aggregate.get("per_class", {})
assert isinstance(per_class, dict), f"per_class shape: {type(per_class)}"
for label, stats in per_class.items():
print(
f"{label:<12} precision={stats['precision']:.4f}"
f" recall={stats['recall']:.4f} f1={stats['f1']:.4f}"
)
per_record = metrics["per_record"]
assert len(per_record) > 0, "per_record must carry one entry per aligned row"
print(f"{len(per_record)} rows scored; the first: {per_record[0]}")biology precision=0.0000 recall=0.0000 f1=0.0000
physics precision=0.4000 recall=1.0000 f1=0.5714
20 rows scored; the first: {'task': 'classification', 'record_id': '1', 'predicted': 'physics', 'gold': 'physics'}
21.6 The predictions alone
Without gold labels, infer runs the model over a source and returns one row per source row, keyed by key, with the model’s outputs as columns.
predictions = db.infer(
source="corpus",
model=MODEL,
columns=["content"],
task="classification",
key="id",
)
assert predictions.num_rows == 20, predictions.num_rows
print(f"{predictions.num_rows} rows, columns {predictions.column_names}")20 rows, columns ['_row_id', '_ordinal', '_source', '_model', '_status', '_error', '_latency_ms', 'label', 'confidence', 'all_scores_json']
db.close()