micm_nlp.evals.results

One evaluation event -> one file, in the run’s output.

save_metrics turns the dict Trainer.evaluate / Trainer.predict returned into <event>.csv (one row per metric group, the run’s static columns stamped on every row); save_predictions turns a predict() output into predictions_<stage>.csv (one row per sample, after the same preprocessing the metric saw). Both write into a RunOutput, once, whole. The trainer calls them; runners never write results themselves.

Functions

event_name(→ str)

base with the stage appended -- test_after_train -- or bare

metric_rows(→ list[dict[str, Any]])

Split one HuggingFace metrics dict into one row per metric group.

save_metrics(→ pathlib.Path | None)

Write one event's metrics as <prefix><event>.csv in the run's output.

save_predictions(→ pathlib.Path)

Write one test pass's predictions as <prefix>predictions_<stage>.csv

write_csv(→ pathlib.Path)

Write rows to path -- header = the union of keys in first-seen order.

Module Contents

micm_nlp.evals.results.event_name(base: str, stage: str | None = None) → str

base with the stage appended – test_after_train – or bare (test) for a run without a training phase, which has one pass per event.

micm_nlp.evals.results.metric_rows(metrics: dict[str, Any], hf_prefix: str, strip: str = '') → list[dict[str, Any]]

Split one HuggingFace metrics dict into one row per metric group.

Keys look like {hf_prefix}_{strip}[{group}/…/]{metric}: the Trainer prepends metric_key_prefix + '_'; the toolkit’s postproc_metrics prepends the unit config’s file name (TRAINER._metric_prefix, passed here as strip); under eval.per_task the group’s task.name comes next. The group is everything between the stripped prefix and the last /; a key with no group (loss) is copied onto every row. Keys with another prefix, and the Trainer’s timing keys, are dropped.

Returns:

rows of {'metric_group', <metrics…>}; empty if no key carried the prefix.

micm_nlp.evals.results.save_metrics(output, event: str, metrics: dict[str, Any], hf_prefix: str, strip: str = '', step: int | None = None) → pathlib.Path | None

Write one event’s metrics as <prefix><event>.csv in the run’s output.

One row per metric group, the run’s static columns stamped on every row, step added when given. Written once, whole; a second write of the same event replaces the file.

The rows are also recorded on output under this event name, so the run is readable in memory in exactly the shape the file holds.

Returns:

the path, or None when no key carried hf_prefix.

micm_nlp.evals.results.save_predictions(output, stage: str | None, pred_out, config, label_pad_id, tokenizer, ds_split, order=None) → pathlib.Path

Write one test pass’s predictions as <prefix>predictions_<stage>.csv (predictions.csv when stage is None).

One row per sample (per token position for token classification), after the same preprocessing the metric saw (preproc_preds_labels()), so every metric is recomputable from the file. sample is the index into the test split – the original index when order (the dataloader’s emit order) is given, else the emit position. Under task.preproc_rules.per_task the rows carry task as well, and sample is still the split index: the per-task groups are re-joined to the split’s order (and to order when given), and the 'all' copy the metrics use is skipped. No static columns: the file lives in the run’s directory, which identifies the run.

micm_nlp.evals.results.write_csv(path: str | pathlib.Path, rows: list[dict[str, Any]]) → pathlib.Path

Write rows to path – header = the union of keys in first-seen order.

Nothing is written for an empty rows.