errorbars 0.1.2__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {errorbars-0.1.2 → errorbars-0.1.3}/CHANGELOG.md +41 -0
- {errorbars-0.1.2 → errorbars-0.1.3}/PKG-INFO +13 -8
- {errorbars-0.1.2 → errorbars-0.1.3}/README.md +12 -7
- {errorbars-0.1.2 → errorbars-0.1.3}/pyproject.toml +1 -1
- {errorbars-0.1.2 → errorbars-0.1.3}/src/errorbars/__init__.py +1 -1
- {errorbars-0.1.2 → errorbars-0.1.3}/src/errorbars/adapters/inspect_ai.py +22 -2
- errorbars-0.1.3/src/errorbars/adapters/lm_eval.py +141 -0
- {errorbars-0.1.2 → errorbars-0.1.3}/src/errorbars/cli.py +12 -1
- {errorbars-0.1.2 → errorbars-0.1.3}/src/errorbars/io.py +29 -3
- {errorbars-0.1.2 → errorbars-0.1.3}/src/errorbars/leaderboard.py +4 -0
- {errorbars-0.1.2 → errorbars-0.1.3}/src/errorbars/power.py +21 -10
- {errorbars-0.1.2 → errorbars-0.1.3}/src/errorbars/stats.py +2 -0
- errorbars-0.1.2/src/errorbars/adapters/lm_eval.py +0 -103
- {errorbars-0.1.2 → errorbars-0.1.3}/.gitignore +0 -0
- {errorbars-0.1.2 → errorbars-0.1.3}/LICENSE +0 -0
- {errorbars-0.1.2 → errorbars-0.1.3}/docs/formulas.md +0 -0
- {errorbars-0.1.2 → errorbars-0.1.3}/src/errorbars/adapters/__init__.py +0 -0
- {errorbars-0.1.2 → errorbars-0.1.3}/src/errorbars/compare.py +0 -0
- {errorbars-0.1.2 → errorbars-0.1.3}/src/errorbars/plot.py +0 -0
- {errorbars-0.1.2 → errorbars-0.1.3}/src/errorbars/py.typed +0 -0
|
@@ -2,6 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.1.3] - 2026-10-01
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- `import lm-eval` on a task with several filters counted every question once
|
|
10
|
+
per filter. `gsm8k_cot_self_consistency` scores each question under
|
|
11
|
+
`score-first`, `maj@8` and `maj@64`, so 4 questions were imported as 12 and
|
|
12
|
+
every standard error shrank accordingly. The adapter now asks which filter to
|
|
13
|
+
use (`--filter maj@8`, or `filter_name=` in Python) and refuses a second
|
|
14
|
+
record for the same `doc_id`. Checked against a real three-filter log from
|
|
15
|
+
lm-eval 0.4.13, committed as a fixture.
|
|
16
|
+
- `import inspect` read a scorer that returns several named values as a score
|
|
17
|
+
of 0 for every sample (that is what Inspect's own conversion does with a
|
|
18
|
+
dict). It is an error now. A score that isn't a finite number is rejected by
|
|
19
|
+
both adapters, as it already was when loading a CSV.
|
|
20
|
+
- A missing or unreadable file printed a Python traceback. It is one line:
|
|
21
|
+
`error: results.csv: No such file or directory`. A file Inspect can't parse
|
|
22
|
+
is named, and so is a JSONL line that isn't an object (it was a
|
|
23
|
+
`TypeError`).
|
|
24
|
+
- A CSV row with too few cells produced a model named `None`; one with too
|
|
25
|
+
many (an unquoted comma in a value) was read with its cells shifted. Both
|
|
26
|
+
are rejected with their row number.
|
|
27
|
+
- `leaderboard --alpha` and `summarize --ci bootstrap --confidence` accepted
|
|
28
|
+
any number, including `nan` and values outside 0 to 1. `power --n` accepted
|
|
29
|
+
a correlation outside -1 to 1 (reported as "math domain error") and a design
|
|
30
|
+
effect below 1, which `power --delta` already refused. Infinite or `nan`
|
|
31
|
+
arguments are refused throughout.
|
|
32
|
+
- Scores too large to square (beyond 1e100) overflowed into `inf` and `nan`
|
|
33
|
+
results, or an `OverflowError`. They are rejected when loading.
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
|
|
37
|
+
- `leaderboard --json` reports `p_value_clustered` for each pair. With
|
|
38
|
+
clustered questions the Holm correction is applied to that p-value, and the
|
|
39
|
+
output only showed the unclustered one, so `p_holm` could not be checked
|
|
40
|
+
against it.
|
|
41
|
+
- A seeded fuzz test runs 1,200 generated datasets and argument sets through
|
|
42
|
+
the command line: each ends in a result that satisfies the basic invariants
|
|
43
|
+
(intervals in order, p-values in 0 to 1, strict JSON) or in a one-line
|
|
44
|
+
error.
|
|
45
|
+
|
|
5
46
|
## [0.1.2] - 2026-10-01
|
|
6
47
|
|
|
7
48
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: errorbars
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Error bars for LLM evals: standard errors, clustering, paired comparisons, leaderboards, and power analysis.
|
|
5
5
|
Project-URL: Homepage, https://antonsoo.github.io/errorbars/
|
|
6
6
|
Project-URL: Repository, https://github.com/antonsoo/errorbars
|
|
@@ -40,6 +40,7 @@ Description-Content-Type: text/markdown
|
|
|
40
40
|
|
|
41
41
|
**Error bars for LLM evals. Know whether model B is actually better, or you're reading noise.**
|
|
42
42
|
|
|
43
|
+
[](https://pypi.org/project/errorbars/)
|
|
43
44
|
[](https://github.com/antonsoo/errorbars/blob/main/LICENSE)
|
|
44
45
|
[](https://antonsoo.github.io/errorbars/)
|
|
45
46
|
[](https://huggingface.co/spaces/antonsoloviev/errorbars)
|
|
@@ -192,15 +193,19 @@ errorbars import inspect logs/<run>.eval -o converted.csv
|
|
|
192
193
|
```
|
|
193
194
|
|
|
194
195
|
`--metric` (lm-eval) picks which computed metric to use as the score when a task reports more than
|
|
195
|
-
one (e.g. `acc` vs. `acc_norm`); it defaults to the first one. `--
|
|
196
|
-
for
|
|
197
|
-
|
|
196
|
+
one (e.g. `acc` vs. `acc_norm`); it defaults to the first one. `--filter` (lm-eval) picks one filter
|
|
197
|
+
for a task that scores every question under several: `gsm8k_cot_self_consistency` logs each question
|
|
198
|
+
three times (`score-first`, `maj@8`, `maj@64`), and reading those as three times the questions would
|
|
199
|
+
shrink every error bar, so the import stops and asks. `--scorer` (Inspect) picks one scorer for
|
|
200
|
+
tasks with more than one. Inspect epochs (`--epochs N`, repeated sampling of the same input) land in
|
|
201
|
+
the `sample` column automatically.
|
|
198
202
|
|
|
199
203
|
Both adapters were built and tested against real, unedited output — not from memory: **lm-eval
|
|
200
204
|
0.4.13** (`lm_eval run --model dummy --tasks copa --limit 20 --log_samples ...`, plus a
|
|
201
|
-
multi-metric `arc_easy` run
|
|
202
|
-
`mockllm/model` provider
|
|
203
|
-
|
|
205
|
+
multi-metric `arc_easy` run and a three-filter `gsm8k_cot_self_consistency` run) and **inspect-ai
|
|
206
|
+
0.3.268** (small tasks through the built-in `mockllm/model` provider: single epoch, two epochs, and
|
|
207
|
+
a scorer with named values). The exact log files are committed as test fixtures
|
|
208
|
+
(`tests/fixtures/samples_*.jsonl`, `tests/fixtures/inspect_*.eval`) and re-parsed in
|
|
204
209
|
`tests/test_adapters.py` on every run. The Inspect adapter reads logs with Inspect's own
|
|
205
210
|
`inspect_ai.log.read_eval_log` and `inspect_ai.scorer.value_to_float` rather than hand-parsing its
|
|
206
211
|
binary `.eval` format, and needs the `inspect` extra:
|
|
@@ -244,7 +249,7 @@ Full derivations with references are in [`docs/formulas.md`](https://github.com/
|
|
|
244
249
|
- Leaderboard groups are maximal cliques of the "not significantly different" graph, which is the
|
|
245
250
|
statistically direct approach — it can produce a model in more than one group, unlike a
|
|
246
251
|
minimal-letters heuristic (e.g. R's `multcompView`).
|
|
247
|
-
-
|
|
252
|
+
- 222 Python tests, 605 TypeScript tests (cross-checking the JS formulas against Python-generated
|
|
248
253
|
vectors), all passing on this box (14 vCPU WSL2 Linux, 48 GB RAM; Python 3.12.3, Node 26.7.0)
|
|
249
254
|
as of 2026-10-01.
|
|
250
255
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Error bars for LLM evals. Know whether model B is actually better, or you're reading noise.**
|
|
4
4
|
|
|
5
|
+
[](https://pypi.org/project/errorbars/)
|
|
5
6
|
[](LICENSE)
|
|
6
7
|
[](https://antonsoo.github.io/errorbars/)
|
|
7
8
|
[](https://huggingface.co/spaces/antonsoloviev/errorbars)
|
|
@@ -154,15 +155,19 @@ errorbars import inspect logs/<run>.eval -o converted.csv
|
|
|
154
155
|
```
|
|
155
156
|
|
|
156
157
|
`--metric` (lm-eval) picks which computed metric to use as the score when a task reports more than
|
|
157
|
-
one (e.g. `acc` vs. `acc_norm`); it defaults to the first one. `--
|
|
158
|
-
for
|
|
159
|
-
|
|
158
|
+
one (e.g. `acc` vs. `acc_norm`); it defaults to the first one. `--filter` (lm-eval) picks one filter
|
|
159
|
+
for a task that scores every question under several: `gsm8k_cot_self_consistency` logs each question
|
|
160
|
+
three times (`score-first`, `maj@8`, `maj@64`), and reading those as three times the questions would
|
|
161
|
+
shrink every error bar, so the import stops and asks. `--scorer` (Inspect) picks one scorer for
|
|
162
|
+
tasks with more than one. Inspect epochs (`--epochs N`, repeated sampling of the same input) land in
|
|
163
|
+
the `sample` column automatically.
|
|
160
164
|
|
|
161
165
|
Both adapters were built and tested against real, unedited output — not from memory: **lm-eval
|
|
162
166
|
0.4.13** (`lm_eval run --model dummy --tasks copa --limit 20 --log_samples ...`, plus a
|
|
163
|
-
multi-metric `arc_easy` run
|
|
164
|
-
`mockllm/model` provider
|
|
165
|
-
|
|
167
|
+
multi-metric `arc_easy` run and a three-filter `gsm8k_cot_self_consistency` run) and **inspect-ai
|
|
168
|
+
0.3.268** (small tasks through the built-in `mockllm/model` provider: single epoch, two epochs, and
|
|
169
|
+
a scorer with named values). The exact log files are committed as test fixtures
|
|
170
|
+
(`tests/fixtures/samples_*.jsonl`, `tests/fixtures/inspect_*.eval`) and re-parsed in
|
|
166
171
|
`tests/test_adapters.py` on every run. The Inspect adapter reads logs with Inspect's own
|
|
167
172
|
`inspect_ai.log.read_eval_log` and `inspect_ai.scorer.value_to_float` rather than hand-parsing its
|
|
168
173
|
binary `.eval` format, and needs the `inspect` extra:
|
|
@@ -206,7 +211,7 @@ Full derivations with references are in [`docs/formulas.md`](docs/formulas.md):
|
|
|
206
211
|
- Leaderboard groups are maximal cliques of the "not significantly different" graph, which is the
|
|
207
212
|
statistically direct approach — it can produce a model in more than one group, unlike a
|
|
208
213
|
minimal-letters heuristic (e.g. R's `multcompView`).
|
|
209
|
-
-
|
|
214
|
+
- 222 Python tests, 605 TypeScript tests (cross-checking the JS formulas against Python-generated
|
|
210
215
|
vectors), all passing on this box (14 vCPU WSL2 Linux, 48 GB RAM; Python 3.12.3, Node 26.7.0)
|
|
211
216
|
as of 2026-10-01.
|
|
212
217
|
|
|
@@ -32,7 +32,7 @@ include = ["/src", "/docs/*.md", "/README.md", "/CHANGELOG.md", "/LICENSE*", "/p
|
|
|
32
32
|
|
|
33
33
|
[project]
|
|
34
34
|
name = "errorbars"
|
|
35
|
-
version = "0.1.
|
|
35
|
+
version = "0.1.3"
|
|
36
36
|
description = "Error bars for LLM evals: standard errors, clustering, paired comparisons, leaderboards, and power analysis."
|
|
37
37
|
dynamic = ["readme"]
|
|
38
38
|
license = "MIT"
|
|
@@ -16,6 +16,7 @@ extra: ``pip install "errorbars[inspect]"``.
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
+
import math
|
|
19
20
|
from pathlib import Path
|
|
20
21
|
|
|
21
22
|
from errorbars.io import EvalData
|
|
@@ -44,7 +45,15 @@ def load_inspect_log(path: str | Path, scorer: str | None = None) -> EvalData:
|
|
|
44
45
|
"load_inspect_log requires inspect-ai (the 'inspect' extra): pip install inspect-ai"
|
|
45
46
|
) from exc
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
try:
|
|
49
|
+
log = read_eval_log(str(path))
|
|
50
|
+
except OSError:
|
|
51
|
+
raise
|
|
52
|
+
except Exception as exc:
|
|
53
|
+
# Inspect reports a file it can't parse in its own terms ("EOCD not found", a list of
|
|
54
|
+
# missing fields); say which file, and that the problem is its format.
|
|
55
|
+
reason = str(exc).strip().splitlines()[0] if str(exc).strip() else type(exc).__name__
|
|
56
|
+
raise ValueError(f"{path}: not a log Inspect can read ({reason})") from exc
|
|
48
57
|
if not log.samples:
|
|
49
58
|
raise ValueError(f"{path}: log has no samples (status={log.status!r})")
|
|
50
59
|
|
|
@@ -72,9 +81,20 @@ def load_inspect_log(path: str | Path, scorer: str | None = None) -> EvalData:
|
|
|
72
81
|
f"{path}: sample {s.id!r} has multiple scorers {list(s.scores)}; "
|
|
73
82
|
"pass `scorer=...` to pick one"
|
|
74
83
|
)
|
|
84
|
+
value = s.scores[key].value
|
|
85
|
+
# value_to_float turns anything it can't read into 0.0. A scorer with several named
|
|
86
|
+
# values has no single score to read, so say so instead of reporting a mean of 0.
|
|
87
|
+
if isinstance(value, (dict, list)):
|
|
88
|
+
raise ValueError(
|
|
89
|
+
f"{path}: sample {s.id!r}: scorer {key!r} returns {type(value).__name__} values "
|
|
90
|
+
f"({value!r}), not one score per sample"
|
|
91
|
+
)
|
|
92
|
+
number = float(to_float(value))
|
|
93
|
+
if not math.isfinite(number):
|
|
94
|
+
raise ValueError(f"{path}: sample {s.id!r}: score {value!r} is not a finite number")
|
|
75
95
|
question_id.append(str(s.id))
|
|
76
96
|
model_col.append(model)
|
|
77
|
-
score.append(
|
|
97
|
+
score.append(number)
|
|
78
98
|
sample_col.append(str(s.epoch))
|
|
79
99
|
|
|
80
100
|
if not question_id:
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""Adapter for lm-evaluation-harness `--log_samples` output.
|
|
2
|
+
|
|
3
|
+
Verified against real output from lm-eval **0.4.13** (the latest stable
|
|
4
|
+
release as of 2026-09-24; there is also a 0.5.0.dev1 prerelease with a
|
|
5
|
+
different CLI we did not target), generated with:
|
|
6
|
+
|
|
7
|
+
lm_eval run --model dummy --tasks copa --limit 20 \\
|
|
8
|
+
--log_samples --output_path <dir>
|
|
9
|
+
|
|
10
|
+
See ``tests/fixtures/samples_copa_*.jsonl`` (single metric: ``acc``),
|
|
11
|
+
``samples_arc_easy_*.jsonl`` (two metrics: ``acc``, ``acc_norm``) and
|
|
12
|
+
``samples_gsm8k_cot_self_consistency_*.jsonl`` (three filters) for the exact,
|
|
13
|
+
unedited records this adapter is built and tested against.
|
|
14
|
+
|
|
15
|
+
Each line of a `--log_samples` file is a JSON object with (at least)::
|
|
16
|
+
|
|
17
|
+
{"doc_id": 0, "doc": {...}, "target": "...", "arguments": {...},
|
|
18
|
+
"resps": [...], "filtered_resps": [...], "filter": "none",
|
|
19
|
+
"metrics": ["acc"], "acc": 1.0, "doc_hash": "...", ...}
|
|
20
|
+
|
|
21
|
+
``metrics`` names which top-level keys on the record hold computed scores
|
|
22
|
+
(a multiple-choice task can report more than one, e.g. ``acc`` and
|
|
23
|
+
``acc_norm``). The samples file has no model name in it (lm-eval's
|
|
24
|
+
``--output_path`` subdirectory can be a content hash rather than a model
|
|
25
|
+
name, e.g. for the ``dummy`` model used here, which has no identifying
|
|
26
|
+
``model_args``), so the caller supplies one.
|
|
27
|
+
|
|
28
|
+
A task with several filters (``gsm8k_cot_self_consistency`` scores each
|
|
29
|
+
question under ``score-first``, ``maj@8`` and ``maj@64``) logs one record per
|
|
30
|
+
question *per filter*. Those are three scorings of the same questions, not
|
|
31
|
+
three times the questions, so one filter has to be chosen.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
from __future__ import annotations
|
|
35
|
+
|
|
36
|
+
import json
|
|
37
|
+
import re
|
|
38
|
+
from pathlib import Path
|
|
39
|
+
|
|
40
|
+
from errorbars.io import EvalData, _coerce_score
|
|
41
|
+
|
|
42
|
+
__all__ = ["load_lm_eval_samples"]
|
|
43
|
+
|
|
44
|
+
# lm-eval's own convention (loggers/evaluation_tracker.py): samples files are
|
|
45
|
+
# named "samples_<task>_<ISO timestamp>.jsonl". Searched rather than anchored
|
|
46
|
+
# to the start so a path prefix (or a renamed-but-suffixed fixture) still matches.
|
|
47
|
+
_TASK_NAME_RE = re.compile(r"samples_(?P<task>.+?)_\d{4}-\d{2}-\d{2}T")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _infer_task_name(path: Path) -> str | None:
|
|
51
|
+
m = _TASK_NAME_RE.search(path.name)
|
|
52
|
+
return m.group("task") if m else None
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def load_lm_eval_samples(
|
|
56
|
+
path: str | Path, model: str, metric: str | None = None, filter_name: str | None = None
|
|
57
|
+
) -> EvalData:
|
|
58
|
+
"""Load an lm-evaluation-harness ``--log_samples`` JSONL file.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
path: path to a ``samples_<task>_<timestamp>.jsonl`` file.
|
|
62
|
+
model: model name to record (lm-eval's samples file doesn't embed
|
|
63
|
+
one usable name for every model type; pass whatever you'd want
|
|
64
|
+
in the ``model`` column).
|
|
65
|
+
metric: which computed metric to use as the score, e.g. ``"acc"``
|
|
66
|
+
or ``"acc_norm"``. Defaults to the first name in each record's
|
|
67
|
+
``metrics`` list.
|
|
68
|
+
filter_name: which filter's records to use, for a task that scores each
|
|
69
|
+
question under several (e.g. ``"maj@8"``). Required when the
|
|
70
|
+
file holds more than one.
|
|
71
|
+
|
|
72
|
+
``question_id`` is the task name (inferred from the filename, if it
|
|
73
|
+
matches lm-eval's naming convention) plus ``doc_id``, e.g.
|
|
74
|
+
``"copa-3"``, so files from different tasks can be safely concatenated.
|
|
75
|
+
"""
|
|
76
|
+
path = Path(path)
|
|
77
|
+
task_name = _infer_task_name(path)
|
|
78
|
+
|
|
79
|
+
records: list[tuple[int, dict[str, object]]] = []
|
|
80
|
+
filters: dict[str, None] = {} # in order of first appearance
|
|
81
|
+
with open(path, encoding="utf-8") as f:
|
|
82
|
+
for lineno, raw_line in enumerate(f, start=1):
|
|
83
|
+
line = raw_line.strip()
|
|
84
|
+
if not line:
|
|
85
|
+
continue
|
|
86
|
+
try:
|
|
87
|
+
rec = json.loads(line)
|
|
88
|
+
except json.JSONDecodeError as exc:
|
|
89
|
+
raise ValueError(f"{path}:{lineno}: invalid JSON: {exc}") from exc
|
|
90
|
+
if not isinstance(rec, dict):
|
|
91
|
+
raise ValueError(
|
|
92
|
+
f"{path}:{lineno}: expected a JSON object per line, got {type(rec).__name__}"
|
|
93
|
+
)
|
|
94
|
+
records.append((lineno, rec))
|
|
95
|
+
filters.setdefault(str(rec.get("filter", "none")))
|
|
96
|
+
|
|
97
|
+
if not records:
|
|
98
|
+
raise ValueError(f"{path}: no records found")
|
|
99
|
+
if filter_name is None and len(filters) > 1:
|
|
100
|
+
raise ValueError(
|
|
101
|
+
f"{path}: the task scores each question under {len(filters)} filters "
|
|
102
|
+
f"({', '.join(filters)}); pick one with filter_name=... (--filter on the command line)"
|
|
103
|
+
)
|
|
104
|
+
if filter_name is not None and filter_name not in filters:
|
|
105
|
+
raise ValueError(f"{path}: no records for filter {filter_name!r} (has: {', '.join(filters)})")
|
|
106
|
+
|
|
107
|
+
question_id: list[str] = []
|
|
108
|
+
model_col: list[str] = []
|
|
109
|
+
score: list[float] = []
|
|
110
|
+
first_line: dict[str, int] = {}
|
|
111
|
+
|
|
112
|
+
for lineno, rec in records:
|
|
113
|
+
if filter_name is not None and str(rec.get("filter", "none")) != filter_name:
|
|
114
|
+
continue
|
|
115
|
+
metrics = rec.get("metrics")
|
|
116
|
+
if not isinstance(metrics, list) or not metrics:
|
|
117
|
+
raise ValueError(f"{path}:{lineno}: record has no non-empty 'metrics' list")
|
|
118
|
+
key = metric or str(metrics[0])
|
|
119
|
+
if key not in rec:
|
|
120
|
+
raise ValueError(
|
|
121
|
+
f"{path}:{lineno}: metric {key!r} not present on this record (available: {metrics})"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
qid = str(rec.get("doc_id", lineno - 1))
|
|
125
|
+
if task_name:
|
|
126
|
+
qid = f"{task_name}-{qid}"
|
|
127
|
+
# The same question twice would count as two questions and shrink every standard error.
|
|
128
|
+
if qid in first_line:
|
|
129
|
+
raise ValueError(
|
|
130
|
+
f"{path}:{lineno}: a second record for doc_id {rec.get('doc_id')!r} "
|
|
131
|
+
f"(first on line {first_line[qid]})"
|
|
132
|
+
)
|
|
133
|
+
first_line[qid] = lineno
|
|
134
|
+
question_id.append(qid)
|
|
135
|
+
model_col.append(model)
|
|
136
|
+
try:
|
|
137
|
+
score.append(_coerce_score(rec[key], lineno))
|
|
138
|
+
except ValueError as exc:
|
|
139
|
+
raise ValueError(f"{path}: metric {key!r}, {str(exc).replace('row', 'line', 1)}") from exc
|
|
140
|
+
|
|
141
|
+
return EvalData(question_id=question_id, model=model_col, score=score)
|
|
@@ -326,7 +326,7 @@ def cmd_import(args: argparse.Namespace) -> None:
|
|
|
326
326
|
raise SystemExit("error: --model is required for the lm-eval adapter")
|
|
327
327
|
from errorbars.adapters.lm_eval import load_lm_eval_samples
|
|
328
328
|
|
|
329
|
-
data = load_lm_eval_samples(args.file, model=args.model, metric=args.metric)
|
|
329
|
+
data = load_lm_eval_samples(args.file, model=args.model, metric=args.metric, filter_name=args.filter)
|
|
330
330
|
elif args.adapter == "inspect":
|
|
331
331
|
try:
|
|
332
332
|
from errorbars.adapters.inspect_ai import load_inspect_log
|
|
@@ -405,6 +405,11 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
405
405
|
p_imp.add_argument(
|
|
406
406
|
"--metric", default=None, help="lm-eval metric to use as the score (default: first available)"
|
|
407
407
|
)
|
|
408
|
+
p_imp.add_argument(
|
|
409
|
+
"--filter",
|
|
410
|
+
default=None,
|
|
411
|
+
help="lm-eval filter to use, for a task that scores each question under several (e.g. maj@8)",
|
|
412
|
+
)
|
|
408
413
|
p_imp.add_argument(
|
|
409
414
|
"--scorer", default=None, help="Inspect scorer to use (default: the only one, if unambiguous)"
|
|
410
415
|
)
|
|
@@ -418,8 +423,14 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
418
423
|
args = parser.parse_args(argv)
|
|
419
424
|
try:
|
|
420
425
|
args.func(args)
|
|
426
|
+
except UnicodeDecodeError as exc:
|
|
427
|
+
raise SystemExit(f"error: the input is not UTF-8 text ({exc})") from exc
|
|
421
428
|
except ValueError as exc:
|
|
422
429
|
raise SystemExit(f"error: {exc}") from exc
|
|
430
|
+
except OSError as exc:
|
|
431
|
+
# A missing or unreadable file is the user's to fix: name it, without a traceback.
|
|
432
|
+
where = f"{exc.filename}: " if exc.filename else ""
|
|
433
|
+
raise SystemExit(f"error: {where}{exc.strerror or exc}") from exc
|
|
423
434
|
|
|
424
435
|
|
|
425
436
|
if __name__ == "__main__":
|
|
@@ -77,6 +77,9 @@ class EvalData:
|
|
|
77
77
|
return out
|
|
78
78
|
|
|
79
79
|
|
|
80
|
+
_MAX_SCORE = 1e100
|
|
81
|
+
|
|
82
|
+
|
|
80
83
|
def _coerce_score(raw: Any, row: int) -> float:
|
|
81
84
|
if isinstance(raw, bool):
|
|
82
85
|
return float(raw)
|
|
@@ -88,9 +91,20 @@ def _coerce_score(raw: Any, row: int) -> float:
|
|
|
88
91
|
# a missing or failed grade has to be decided on explicitly, not averaged in as "not a number".
|
|
89
92
|
if not math.isfinite(value):
|
|
90
93
|
raise ValueError(f"row {row}: score {raw!r} is not a finite number")
|
|
94
|
+
# Variances square the scores: beyond this they overflow to infinity.
|
|
95
|
+
if abs(value) > _MAX_SCORE:
|
|
96
|
+
raise ValueError(f"row {row}: score {raw!r} is too large to analyze (limit {_MAX_SCORE:g})")
|
|
91
97
|
return value
|
|
92
98
|
|
|
93
99
|
|
|
100
|
+
def _label(row: Any, column: str, n: int) -> str:
|
|
101
|
+
value = row[column]
|
|
102
|
+
# csv.DictReader fills the cells a short row lacks with None.
|
|
103
|
+
if value is None:
|
|
104
|
+
raise ValueError(f"row {n}: no value for column '{column}' (the row has too few fields)")
|
|
105
|
+
return str(value)
|
|
106
|
+
|
|
107
|
+
|
|
94
108
|
def _from_records(records: Iterable[dict[str, Any]], columns: ColumnMap) -> EvalData:
|
|
95
109
|
question_id: list[str] = []
|
|
96
110
|
model: list[str] = []
|
|
@@ -102,14 +116,21 @@ def _from_records(records: Iterable[dict[str, Any]], columns: ColumnMap) -> Eval
|
|
|
102
116
|
seen: dict[tuple[str, str, str], int] = {}
|
|
103
117
|
for row in records:
|
|
104
118
|
n += 1
|
|
119
|
+
if not isinstance(row, dict):
|
|
120
|
+
raise ValueError(f"row {n}: expected a record with named fields, got {type(row).__name__}")
|
|
121
|
+
# csv.DictReader collects the cells beyond the header under the key None.
|
|
122
|
+
if None in row:
|
|
123
|
+
raise ValueError(
|
|
124
|
+
f"row {n}: more fields than the header has columns (an unquoted comma in a value?)"
|
|
125
|
+
)
|
|
105
126
|
if columns.question_id not in row:
|
|
106
127
|
raise ValueError(f"missing required column '{columns.question_id}' in row {n}")
|
|
107
128
|
if columns.model not in row:
|
|
108
129
|
raise ValueError(f"missing required column '{columns.model}' in row {n}")
|
|
109
130
|
if columns.score not in row:
|
|
110
131
|
raise ValueError(f"missing required column '{columns.score}' in row {n}")
|
|
111
|
-
question_id.append(
|
|
112
|
-
model.append(
|
|
132
|
+
question_id.append(_label(row, columns.question_id, n))
|
|
133
|
+
model.append(_label(row, columns.model, n))
|
|
113
134
|
score.append(_coerce_score(row[columns.score], n))
|
|
114
135
|
if cluster_id is not None and columns.cluster_id is not None:
|
|
115
136
|
cluster_id.append(str(row.get(columns.cluster_id, question_id[-1])))
|
|
@@ -152,9 +173,14 @@ def load_jsonl(path: str | Path, columns: ColumnMap | None = None) -> EvalData:
|
|
|
152
173
|
if not line:
|
|
153
174
|
continue
|
|
154
175
|
try:
|
|
155
|
-
|
|
176
|
+
record = json.loads(line)
|
|
156
177
|
except json.JSONDecodeError as exc:
|
|
157
178
|
raise ValueError(f"{path}:{lineno}: invalid JSON: {exc}") from exc
|
|
179
|
+
if not isinstance(record, dict):
|
|
180
|
+
raise ValueError(
|
|
181
|
+
f"{path}:{lineno}: expected a JSON object per line, got {type(record).__name__}"
|
|
182
|
+
)
|
|
183
|
+
records.append(record)
|
|
158
184
|
if not records:
|
|
159
185
|
raise ValueError(f"{path}: no records found")
|
|
160
186
|
return _from_records(records, columns)
|
|
@@ -66,6 +66,8 @@ class PairwiseResult:
|
|
|
66
66
|
"model_b": self.model_b,
|
|
67
67
|
"mean_diff": self.comparison.mean_diff,
|
|
68
68
|
"p_value": self.comparison.p_value,
|
|
69
|
+
# The Holm correction is applied to this one when the questions are clustered.
|
|
70
|
+
"p_value_clustered": self.comparison.p_value_clustered,
|
|
69
71
|
"p_holm": self.p_holm,
|
|
70
72
|
}
|
|
71
73
|
|
|
@@ -127,6 +129,8 @@ def build_leaderboard(
|
|
|
127
129
|
models = data.models()
|
|
128
130
|
if len(models) < 2:
|
|
129
131
|
raise ValueError("leaderboard needs at least 2 models")
|
|
132
|
+
if not 0.0 < alpha < 1.0:
|
|
133
|
+
raise ValueError(f"alpha must be in (0, 1), got {alpha}")
|
|
130
134
|
|
|
131
135
|
per_model_scores: dict[str, list[float]] = {m: data.filter_model(m).score for m in models}
|
|
132
136
|
|
|
@@ -49,8 +49,8 @@ def per_question_variance(
|
|
|
49
49
|
if baseline_accuracy is not None and not 0.0 < baseline_accuracy < 1.0:
|
|
50
50
|
# p(1-p) is 0 at either end, which would make any gap look free to detect.
|
|
51
51
|
raise ValueError(f"baseline_accuracy must be strictly between 0 and 1, got {baseline_accuracy}")
|
|
52
|
-
if variance is not None and not variance > 0:
|
|
53
|
-
raise ValueError(f"variance must be positive, got {variance}")
|
|
52
|
+
if variance is not None and not (variance > 0 and math.isfinite(variance)):
|
|
53
|
+
raise ValueError(f"variance must be a positive, finite number, got {variance}")
|
|
54
54
|
v = baseline_accuracy * (1 - baseline_accuracy) if baseline_accuracy is not None else variance
|
|
55
55
|
return v / samples_per_question # type: ignore[operator]
|
|
56
56
|
|
|
@@ -85,6 +85,19 @@ def _z_beta(power: float) -> float:
|
|
|
85
85
|
return _NORMAL.inv_cdf(power) # one-sided: z such that Phi(z) = power
|
|
86
86
|
|
|
87
87
|
|
|
88
|
+
def _z_alpha(alpha: float) -> float:
|
|
89
|
+
if not 0.0 < alpha < 1.0:
|
|
90
|
+
raise ValueError(f"alpha must be in (0, 1), got {alpha}")
|
|
91
|
+
return z_for_confidence(1 - alpha)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _check_design(rho: float, cluster_design_effect: float) -> None:
|
|
95
|
+
if not -1.0 <= rho <= 1.0:
|
|
96
|
+
raise ValueError(f"rho must be in [-1, 1], got {rho}")
|
|
97
|
+
if not (cluster_design_effect >= 1.0 and math.isfinite(cluster_design_effect)):
|
|
98
|
+
raise ValueError(f"cluster_design_effect must be a finite number >= 1, got {cluster_design_effect}")
|
|
99
|
+
|
|
100
|
+
|
|
88
101
|
def questions_needed(
|
|
89
102
|
delta: float,
|
|
90
103
|
baseline_accuracy: float | None = None,
|
|
@@ -100,18 +113,15 @@ def questions_needed(
|
|
|
100
113
|
``n = (z_{a/2} + z_b)^2 * 2*V*(1-rho) * deff / delta^2`` where V is the
|
|
101
114
|
per-question variance (see ``per_question_variance``).
|
|
102
115
|
"""
|
|
103
|
-
if delta
|
|
104
|
-
raise ValueError("delta must be positive")
|
|
105
|
-
|
|
106
|
-
raise ValueError("rho must be in [-1, 1]")
|
|
107
|
-
if cluster_design_effect < 1.0:
|
|
108
|
-
raise ValueError("cluster_design_effect must be >= 1")
|
|
116
|
+
if not (delta > 0 and math.isfinite(delta)):
|
|
117
|
+
raise ValueError(f"delta must be a positive, finite number, got {delta}")
|
|
118
|
+
_check_design(rho, cluster_design_effect)
|
|
109
119
|
v = per_question_variance(baseline_accuracy, variance, samples_per_question)
|
|
110
120
|
if baseline_accuracy is not None and baseline_accuracy + delta > 1.0:
|
|
111
121
|
raise ValueError(
|
|
112
122
|
f"baseline_accuracy + delta = {baseline_accuracy + delta:.3g}: an accuracy can't exceed 1"
|
|
113
123
|
)
|
|
114
|
-
z_a =
|
|
124
|
+
z_a = _z_alpha(alpha)
|
|
115
125
|
z_b = _z_beta(power)
|
|
116
126
|
n = ((z_a + z_b) ** 2) * 2 * v * (1 - rho) * cluster_design_effect / (delta**2)
|
|
117
127
|
n_int = max(2, math.ceil(n))
|
|
@@ -131,7 +141,8 @@ def minimum_detectable_effect(
|
|
|
131
141
|
"""Smallest paired difference detectable with a given n, alpha, power."""
|
|
132
142
|
if n_questions < 2:
|
|
133
143
|
raise ValueError("n_questions must be >= 2")
|
|
144
|
+
_check_design(rho, cluster_design_effect)
|
|
134
145
|
v = per_question_variance(baseline_accuracy, variance, samples_per_question)
|
|
135
|
-
z_a =
|
|
146
|
+
z_a = _z_alpha(alpha)
|
|
136
147
|
z_b = _z_beta(power)
|
|
137
148
|
return (z_a + z_b) * math.sqrt(2 * v * (1 - rho) * cluster_design_effect / n_questions)
|
|
@@ -195,6 +195,8 @@ def bootstrap_ci(
|
|
|
195
195
|
n = arr.size
|
|
196
196
|
if n < 2:
|
|
197
197
|
raise ValueError("need at least 2 observations to bootstrap")
|
|
198
|
+
if not 0.0 < confidence < 1.0:
|
|
199
|
+
raise ValueError(f"confidence must be in (0, 1), got {confidence}")
|
|
198
200
|
rng = np.random.default_rng(seed)
|
|
199
201
|
idx = rng.integers(0, n, size=(n_boot, n))
|
|
200
202
|
boot_means = arr[idx].mean(axis=1)
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"""Adapter for lm-evaluation-harness `--log_samples` output.
|
|
2
|
-
|
|
3
|
-
Verified against real output from lm-eval **0.4.13** (the latest stable
|
|
4
|
-
release as of 2026-09-24; there is also a 0.5.0.dev1 prerelease with a
|
|
5
|
-
different CLI we did not target), generated with:
|
|
6
|
-
|
|
7
|
-
lm_eval run --model dummy --tasks copa --limit 20 \\
|
|
8
|
-
--log_samples --output_path <dir>
|
|
9
|
-
|
|
10
|
-
See ``tests/fixtures/lm_eval_samples_copa.jsonl`` (single metric: ``acc``)
|
|
11
|
-
and ``tests/fixtures/lm_eval_samples_arc_easy.jsonl`` (two metrics: ``acc``,
|
|
12
|
-
``acc_norm``) for the exact, unedited records this adapter is built and
|
|
13
|
-
tested against.
|
|
14
|
-
|
|
15
|
-
Each line of a `--log_samples` file is a JSON object with (at least)::
|
|
16
|
-
|
|
17
|
-
{"doc_id": 0, "doc": {...}, "target": "...", "arguments": {...},
|
|
18
|
-
"resps": [...], "filtered_resps": [...], "filter": "none",
|
|
19
|
-
"metrics": ["acc"], "acc": 1.0, "doc_hash": "...", ...}
|
|
20
|
-
|
|
21
|
-
``metrics`` names which top-level keys on the record hold computed scores
|
|
22
|
-
(a multiple-choice task can report more than one, e.g. ``acc`` and
|
|
23
|
-
``acc_norm``). The samples file has no model name in it (lm-eval's
|
|
24
|
-
``--output_path`` subdirectory can be a content hash rather than a model
|
|
25
|
-
name, e.g. for the ``dummy`` model used here, which has no identifying
|
|
26
|
-
``model_args``), so the caller supplies one.
|
|
27
|
-
"""
|
|
28
|
-
|
|
29
|
-
from __future__ import annotations
|
|
30
|
-
|
|
31
|
-
import json
|
|
32
|
-
import re
|
|
33
|
-
from pathlib import Path
|
|
34
|
-
|
|
35
|
-
from errorbars.io import EvalData
|
|
36
|
-
|
|
37
|
-
__all__ = ["load_lm_eval_samples"]
|
|
38
|
-
|
|
39
|
-
# lm-eval's own convention (loggers/evaluation_tracker.py): samples files are
|
|
40
|
-
# named "samples_<task>_<ISO timestamp>.jsonl". Searched rather than anchored
|
|
41
|
-
# to the start so a path prefix (or a renamed-but-suffixed fixture) still matches.
|
|
42
|
-
_TASK_NAME_RE = re.compile(r"samples_(?P<task>.+?)_\d{4}-\d{2}-\d{2}T")
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def _infer_task_name(path: Path) -> str | None:
|
|
46
|
-
m = _TASK_NAME_RE.search(path.name)
|
|
47
|
-
return m.group("task") if m else None
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def load_lm_eval_samples(path: str | Path, model: str, metric: str | None = None) -> EvalData:
|
|
51
|
-
"""Load an lm-evaluation-harness ``--log_samples`` JSONL file.
|
|
52
|
-
|
|
53
|
-
Args:
|
|
54
|
-
path: path to a ``samples_<task>_<timestamp>.jsonl`` file.
|
|
55
|
-
model: model name to record (lm-eval's samples file doesn't embed
|
|
56
|
-
one usable name for every model type; pass whatever you'd want
|
|
57
|
-
in the ``model`` column).
|
|
58
|
-
metric: which computed metric to use as the score, e.g. ``"acc"``
|
|
59
|
-
or ``"acc_norm"``. Defaults to the first name in each record's
|
|
60
|
-
``metrics`` list.
|
|
61
|
-
|
|
62
|
-
``question_id`` is the task name (inferred from the filename, if it
|
|
63
|
-
matches lm-eval's naming convention) plus ``doc_id``, e.g.
|
|
64
|
-
``"copa-3"``, so files from different tasks can be safely concatenated.
|
|
65
|
-
"""
|
|
66
|
-
path = Path(path)
|
|
67
|
-
task_name = _infer_task_name(path)
|
|
68
|
-
|
|
69
|
-
question_id: list[str] = []
|
|
70
|
-
model_col: list[str] = []
|
|
71
|
-
score: list[float] = []
|
|
72
|
-
|
|
73
|
-
with open(path, encoding="utf-8") as f:
|
|
74
|
-
for lineno, raw_line in enumerate(f, start=1):
|
|
75
|
-
line = raw_line.strip()
|
|
76
|
-
if not line:
|
|
77
|
-
continue
|
|
78
|
-
try:
|
|
79
|
-
rec = json.loads(line)
|
|
80
|
-
except json.JSONDecodeError as exc:
|
|
81
|
-
raise ValueError(f"{path}:{lineno}: invalid JSON: {exc}") from exc
|
|
82
|
-
|
|
83
|
-
metrics = rec.get("metrics")
|
|
84
|
-
if not metrics:
|
|
85
|
-
raise ValueError(f"{path}:{lineno}: record has no non-empty 'metrics' list")
|
|
86
|
-
key = metric or metrics[0]
|
|
87
|
-
if key not in rec:
|
|
88
|
-
raise ValueError(
|
|
89
|
-
f"{path}:{lineno}: metric {key!r} not present on this record "
|
|
90
|
-
f"(available: {metrics})"
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
qid = str(rec.get("doc_id", lineno - 1))
|
|
94
|
-
if task_name:
|
|
95
|
-
qid = f"{task_name}-{qid}"
|
|
96
|
-
question_id.append(qid)
|
|
97
|
-
model_col.append(model)
|
|
98
|
-
score.append(float(rec[key]))
|
|
99
|
-
|
|
100
|
-
if not question_id:
|
|
101
|
-
raise ValueError(f"{path}: no records found")
|
|
102
|
-
|
|
103
|
-
return EvalData(question_id=question_id, model=model_col, score=score)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|