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¶
|
|
|
Split one HuggingFace metrics dict into one row per metric group. |
|
Write one event's metrics as |
|
Write one test pass's predictions as |
|
Write |
Module Contents¶
- micm_nlp.evals.results.event_name(base: str, stage: str | None = None) str¶
basewith 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 prependsmetric_key_prefix + '_'; the toolkit’spostproc_metricsprepends the unit config’s file name (TRAINER._metric_prefix, passed here asstrip); undereval.per_taskthe group’stask.namecomes 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>.csvin the run’s output.One row per metric group, the run’s static columns stamped on every row,
stepadded when given. Written once, whole; a second write of the same event replaces the file.The rows are also recorded on
outputunder this event name, so the run is readable in memory in exactly the shape the file holds.- Returns:
the path, or
Nonewhen no key carriedhf_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.csvwhenstageisNone).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.sampleis the index into the test split – the original index whenorder(the dataloader’s emit order) is given, else the emit position. Undertask.preproc_rules.per_taskthe rows carrytaskas well, andsampleis still the split index: the per-task groups are re-joined to the split’s order (and toorderwhen 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
rowstopath– header = the union of keys in first-seen order.Nothing is written for an empty
rows.