errorbars 0.1.3__tar.gz → 0.2.0__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.3 → errorbars-0.2.0}/CHANGELOG.md +41 -0
- {errorbars-0.1.3 → errorbars-0.2.0}/PKG-INFO +58 -18
- {errorbars-0.1.3 → errorbars-0.2.0}/README.md +57 -17
- {errorbars-0.1.3 → errorbars-0.2.0}/pyproject.toml +1 -1
- {errorbars-0.1.3 → errorbars-0.2.0}/src/errorbars/__init__.py +3 -1
- {errorbars-0.1.3 → errorbars-0.2.0}/src/errorbars/adapters/lm_eval.py +68 -9
- {errorbars-0.1.3 → errorbars-0.2.0}/src/errorbars/cli.py +122 -54
- errorbars-0.2.0/src/errorbars/inputs.py +180 -0
- {errorbars-0.1.3 → errorbars-0.2.0}/src/errorbars/io.py +62 -1
- {errorbars-0.1.3 → errorbars-0.2.0}/.gitignore +0 -0
- {errorbars-0.1.3 → errorbars-0.2.0}/LICENSE +0 -0
- {errorbars-0.1.3 → errorbars-0.2.0}/docs/formulas.md +0 -0
- {errorbars-0.1.3 → errorbars-0.2.0}/src/errorbars/adapters/__init__.py +0 -0
- {errorbars-0.1.3 → errorbars-0.2.0}/src/errorbars/adapters/inspect_ai.py +0 -0
- {errorbars-0.1.3 → errorbars-0.2.0}/src/errorbars/compare.py +0 -0
- {errorbars-0.1.3 → errorbars-0.2.0}/src/errorbars/leaderboard.py +0 -0
- {errorbars-0.1.3 → errorbars-0.2.0}/src/errorbars/plot.py +0 -0
- {errorbars-0.1.3 → errorbars-0.2.0}/src/errorbars/power.py +0 -0
- {errorbars-0.1.3 → errorbars-0.2.0}/src/errorbars/py.typed +0 -0
- {errorbars-0.1.3 → errorbars-0.2.0}/src/errorbars/stats.py +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.2.0] - 2026-10-01
|
|
6
|
+
|
|
7
|
+
A harness writes one log per model, and every command took exactly one file. Asking whether
|
|
8
|
+
model B beats model A, starting from real lm-eval output, was two `import` runs, a
|
|
9
|
+
hand-made concatenation of two CSVs, and then `compare`.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `summarize`, `compare` and `leaderboard` take one or more files or directories and read
|
|
14
|
+
each as what it is: errorbars' CSV/JSONL, an lm-evaluation-harness `samples_*.jsonl`, or
|
|
15
|
+
an Inspect AI `.eval` log. `errorbars compare out/model-a out/model-b` is the whole
|
|
16
|
+
comparison; `errorbars leaderboard out` ranks every model under an lm-eval output
|
|
17
|
+
directory. Checked against the output directory of two real lm-eval 0.4.13 runs
|
|
18
|
+
(`--model hf`, two tiny models, COPA), committed as a fixture: the means are the
|
|
19
|
+
accuracies lm-eval reported.
|
|
20
|
+
- The model of an lm-eval samples file is read from the `results_<timestamp>.json` lm-eval
|
|
21
|
+
writes beside it (`model_name`), so `--model` is no longer required. A samples file moved
|
|
22
|
+
away from its results file has to be named, as `NAME=PATH`; the same form tells two runs of
|
|
23
|
+
one model apart (`greedy=a.eval sampled=b.eval`).
|
|
24
|
+
- A directory with several runs of one task (lm-eval adds a timestamped file on every
|
|
25
|
+
re-run) uses the latest and says so on stderr.
|
|
26
|
+
- The same model, question and sample in two inputs is refused and both files are named.
|
|
27
|
+
- `compare` with exactly two models in the input needs no `--model-a`/`--model-b`. Its
|
|
28
|
+
output says how many questions only one of the two models answered (`n_only_a`,
|
|
29
|
+
`n_only_b` in `--json`), and `leaderboard` says when the models were not scored on the same
|
|
30
|
+
questions.
|
|
31
|
+
- `import` takes several logs and directories and writes one CSV. `--metric`, `--filter`
|
|
32
|
+
and `--scorer` are available on every command that reads logs.
|
|
33
|
+
- Python: `errorbars.load_inputs`, `errorbars.io.concat`,
|
|
34
|
+
`errorbars.adapters.lm_eval.infer_model_name`.
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- `summarize` on a file without a `cluster_id` column printed clustering diagnostics anyway,
|
|
39
|
+
with every question as its own cluster: for 4 questions, "n clusters 4" and a "clustered
|
|
40
|
+
CI" of [-0.05, 1.55]. Diagnostics now need a cluster that groups questions.
|
|
41
|
+
- `summarize` without `--model` on a file with several models pooled them: the example
|
|
42
|
+
benchmark's 4 models x 200 questions were summarized as one sample of n = 800 (SE 0.017,
|
|
43
|
+
where each model's is 0.033 to 0.035). It now asks which model, or points to `leaderboard`.
|
|
44
|
+
With one model in the data, the summary is titled with its name instead of `(all)`.
|
|
45
|
+
|
|
5
46
|
## [0.1.3] - 2026-10-01
|
|
6
47
|
|
|
7
48
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: errorbars
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
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
|
|
@@ -103,8 +103,11 @@ errorbars leaderboard examples/data/reading_comprehension.csv
|
|
|
103
103
|
and cluster design effect.
|
|
104
104
|
- **CLI** — `errorbars summarize|compare|leaderboard|power|import`, `rich` tables by default,
|
|
105
105
|
`--json` for scripting.
|
|
106
|
-
- **
|
|
107
|
-
|
|
106
|
+
- **Reads what harnesses write** — a harness leaves one log per model, so every command takes
|
|
107
|
+
one or more files or directories and reads each as what it is: lm-evaluation-harness
|
|
108
|
+
`--log_samples` output, Inspect AI `.eval` logs, or the CSV/JSONL format below.
|
|
109
|
+
`errorbars compare out/model-a out/model-b` is the whole comparison (see
|
|
110
|
+
[below](#reading-lm-evaluation-harness-and-inspect-ai-logs)).
|
|
108
111
|
- **Web calculator** — a static "how many eval questions do I need?" power calculator
|
|
109
112
|
([live demo](https://antonsoo.github.io/errorbars/)), whose TypeScript formulas are checked
|
|
110
113
|
against the Python ones by the test suite.
|
|
@@ -179,34 +182,71 @@ Column names are configurable (`--question-col`, `--cluster-col`, etc., or `Colu
|
|
|
179
182
|
Scores can be binary (0/1) or continuous. `cluster_id` groups correlated questions (e.g. several
|
|
180
183
|
questions per reading passage); `sample` marks repeated generations of the same question.
|
|
181
184
|
|
|
182
|
-
|
|
185
|
+
Every command takes several files (`errorbars leaderboard model-a.csv model-b.csv ...`) and puts
|
|
186
|
+
their rows together. The same model, question and sample in two files is refused, as it is within
|
|
187
|
+
one file: counted twice it would inflate n and shrink every error bar.
|
|
183
188
|
|
|
184
|
-
|
|
189
|
+
### Reading lm-evaluation-harness and Inspect AI logs
|
|
190
|
+
|
|
191
|
+
A harness writes one log per model and per task, so "is B better than A" starts from two files.
|
|
192
|
+
`summarize`, `compare` and `leaderboard` read them as they are:
|
|
185
193
|
|
|
186
194
|
```bash
|
|
187
|
-
# lm-evaluation-harness: lm_eval run --model
|
|
188
|
-
|
|
189
|
-
|
|
195
|
+
# lm-evaluation-harness: lm_eval run --model hf --model_args pretrained=<model> --tasks copa \
|
|
196
|
+
# --log_samples --output_path out (one directory per model)
|
|
197
|
+
errorbars compare out/sshleifer__tiny-gpt2 out/hf-internal-testing__tiny-random-gpt2
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
│ n (shared questions) │ 20 │
|
|
202
|
+
│ mean(sshleifer/tiny-gpt2) │ 0.6000 │
|
|
203
|
+
│ mean(hf-internal-testing/tiny-random-gpt2) │ 0.8000 │
|
|
204
|
+
│ mean diff (A - B) │ -0.2000 │
|
|
205
|
+
│ paired SE │ 0.1376 │
|
|
206
|
+
│ 95% CI │ [-0.4881, 0.0881] │
|
|
207
|
+
│ p-value │ 0.1625 │
|
|
208
|
+
│ McNemar discordant (A wrong/B right, A right/B wrong) │ 6 / 2 │
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
That is a real run, committed under `tests/fixtures/lm_eval_output/` (two tiny models, 20 COPA
|
|
212
|
+
questions). lm-eval's own table says 0.6 ± 0.11 and 0.8 ± 0.09; the paired test on the same 20
|
|
213
|
+
answers gives p = 0.16, so the 20-point gap is not evidence yet. (Rows trimmed; the command prints
|
|
214
|
+
a few more.)
|
|
190
215
|
|
|
191
|
-
|
|
192
|
-
errorbars
|
|
216
|
+
```bash
|
|
217
|
+
errorbars leaderboard out # every model under the output directory
|
|
218
|
+
errorbars compare logs/run-a.eval logs/run-b.eval # Inspect AI logs
|
|
219
|
+
errorbars compare greedy=logs/a.eval sampled=logs/b.eval # two runs of one model, told apart
|
|
220
|
+
errorbars import lm-eval out -o all.csv # or write the canonical CSV once and keep it
|
|
193
221
|
```
|
|
194
222
|
|
|
223
|
+
- **lm-eval**: a `samples_<task>_<timestamp>.jsonl` file, a model's directory, or the whole
|
|
224
|
+
`--output_path`. The samples file does not name its model; lm-eval writes it beside a
|
|
225
|
+
`results_<timestamp>.json` that does, and that is where the name comes from. A samples file
|
|
226
|
+
moved away from it has to be named: `my-model=path/to/samples_copa_....jsonl`. When a directory
|
|
227
|
+
holds several runs of a task, the latest is used and a note says so. Question ids are
|
|
228
|
+
`<task>-<doc_id>`, so several tasks of one model add up to one benchmark.
|
|
229
|
+
- **Inspect AI**: `.eval` (or `.json`) logs; the model is the one in the log. Epochs (`--epochs N`,
|
|
230
|
+
repeated sampling of the same input) land in the `sample` column automatically.
|
|
231
|
+
- With exactly two models in the input, `compare` needs no `--model-a`/`--model-b`: A is the first
|
|
232
|
+
one given. When the two were not scored on the same questions (a different `--limit`, a run
|
|
233
|
+
that crashed), the comparison uses the shared ones and reports how many were left out.
|
|
234
|
+
|
|
195
235
|
`--metric` (lm-eval) picks which computed metric to use as the score when a task reports more than
|
|
196
236
|
one (e.g. `acc` vs. `acc_norm`); it defaults to the first one. `--filter` (lm-eval) picks one filter
|
|
197
237
|
for a task that scores every question under several: `gsm8k_cot_self_consistency` logs each question
|
|
198
238
|
three times (`score-first`, `maj@8`, `maj@64`), and reading those as three times the questions would
|
|
199
239
|
shrink every error bar, so the import stops and asks. `--scorer` (Inspect) picks one scorer for
|
|
200
|
-
tasks with more than one.
|
|
201
|
-
the `sample` column automatically.
|
|
240
|
+
tasks with more than one.
|
|
202
241
|
|
|
203
242
|
Both adapters were built and tested against real, unedited output — not from memory: **lm-eval
|
|
204
|
-
0.4.13** (`lm_eval run --model dummy --tasks copa --limit 20 --log_samples ...`,
|
|
205
|
-
|
|
206
|
-
0.3.268** (small tasks through the built-in `mockllm/model` provider: single
|
|
207
|
-
a scorer with named values). The exact log files are committed as test
|
|
208
|
-
(`tests/fixtures/samples_*.jsonl`, `tests/fixtures/
|
|
209
|
-
`tests/
|
|
243
|
+
0.4.13** (`lm_eval run --model dummy --tasks copa --limit 20 --log_samples ...`, a multi-metric
|
|
244
|
+
`arc_easy` run, a three-filter `gsm8k_cot_self_consistency` run, and the two-model output directory
|
|
245
|
+
above) and **inspect-ai 0.3.268** (small tasks through the built-in `mockllm/model` provider: single
|
|
246
|
+
epoch, two epochs, and a scorer with named values). The exact log files are committed as test
|
|
247
|
+
fixtures (`tests/fixtures/samples_*.jsonl`, `tests/fixtures/lm_eval_output/`,
|
|
248
|
+
`tests/fixtures/inspect_*.eval`) and re-parsed in `tests/test_adapters.py` and
|
|
249
|
+
`tests/test_inputs.py` on every run. The Inspect adapter reads logs with Inspect's own
|
|
210
250
|
`inspect_ai.log.read_eval_log` and `inspect_ai.scorer.value_to_float` rather than hand-parsing its
|
|
211
251
|
binary `.eval` format, and needs the `inspect` extra:
|
|
212
252
|
`pip install "errorbars[inspect]"`. The lm-eval
|
|
@@ -65,8 +65,11 @@ errorbars leaderboard examples/data/reading_comprehension.csv
|
|
|
65
65
|
and cluster design effect.
|
|
66
66
|
- **CLI** — `errorbars summarize|compare|leaderboard|power|import`, `rich` tables by default,
|
|
67
67
|
`--json` for scripting.
|
|
68
|
-
- **
|
|
69
|
-
|
|
68
|
+
- **Reads what harnesses write** — a harness leaves one log per model, so every command takes
|
|
69
|
+
one or more files or directories and reads each as what it is: lm-evaluation-harness
|
|
70
|
+
`--log_samples` output, Inspect AI `.eval` logs, or the CSV/JSONL format below.
|
|
71
|
+
`errorbars compare out/model-a out/model-b` is the whole comparison (see
|
|
72
|
+
[below](#reading-lm-evaluation-harness-and-inspect-ai-logs)).
|
|
70
73
|
- **Web calculator** — a static "how many eval questions do I need?" power calculator
|
|
71
74
|
([live demo](https://antonsoo.github.io/errorbars/)), whose TypeScript formulas are checked
|
|
72
75
|
against the Python ones by the test suite.
|
|
@@ -141,34 +144,71 @@ Column names are configurable (`--question-col`, `--cluster-col`, etc., or `Colu
|
|
|
141
144
|
Scores can be binary (0/1) or continuous. `cluster_id` groups correlated questions (e.g. several
|
|
142
145
|
questions per reading passage); `sample` marks repeated generations of the same question.
|
|
143
146
|
|
|
144
|
-
|
|
147
|
+
Every command takes several files (`errorbars leaderboard model-a.csv model-b.csv ...`) and puts
|
|
148
|
+
their rows together. The same model, question and sample in two files is refused, as it is within
|
|
149
|
+
one file: counted twice it would inflate n and shrink every error bar.
|
|
145
150
|
|
|
146
|
-
|
|
151
|
+
### Reading lm-evaluation-harness and Inspect AI logs
|
|
152
|
+
|
|
153
|
+
A harness writes one log per model and per task, so "is B better than A" starts from two files.
|
|
154
|
+
`summarize`, `compare` and `leaderboard` read them as they are:
|
|
147
155
|
|
|
148
156
|
```bash
|
|
149
|
-
# lm-evaluation-harness: lm_eval run --model
|
|
150
|
-
|
|
151
|
-
|
|
157
|
+
# lm-evaluation-harness: lm_eval run --model hf --model_args pretrained=<model> --tasks copa \
|
|
158
|
+
# --log_samples --output_path out (one directory per model)
|
|
159
|
+
errorbars compare out/sshleifer__tiny-gpt2 out/hf-internal-testing__tiny-random-gpt2
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
│ n (shared questions) │ 20 │
|
|
164
|
+
│ mean(sshleifer/tiny-gpt2) │ 0.6000 │
|
|
165
|
+
│ mean(hf-internal-testing/tiny-random-gpt2) │ 0.8000 │
|
|
166
|
+
│ mean diff (A - B) │ -0.2000 │
|
|
167
|
+
│ paired SE │ 0.1376 │
|
|
168
|
+
│ 95% CI │ [-0.4881, 0.0881] │
|
|
169
|
+
│ p-value │ 0.1625 │
|
|
170
|
+
│ McNemar discordant (A wrong/B right, A right/B wrong) │ 6 / 2 │
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
That is a real run, committed under `tests/fixtures/lm_eval_output/` (two tiny models, 20 COPA
|
|
174
|
+
questions). lm-eval's own table says 0.6 ± 0.11 and 0.8 ± 0.09; the paired test on the same 20
|
|
175
|
+
answers gives p = 0.16, so the 20-point gap is not evidence yet. (Rows trimmed; the command prints
|
|
176
|
+
a few more.)
|
|
152
177
|
|
|
153
|
-
|
|
154
|
-
errorbars
|
|
178
|
+
```bash
|
|
179
|
+
errorbars leaderboard out # every model under the output directory
|
|
180
|
+
errorbars compare logs/run-a.eval logs/run-b.eval # Inspect AI logs
|
|
181
|
+
errorbars compare greedy=logs/a.eval sampled=logs/b.eval # two runs of one model, told apart
|
|
182
|
+
errorbars import lm-eval out -o all.csv # or write the canonical CSV once and keep it
|
|
155
183
|
```
|
|
156
184
|
|
|
185
|
+
- **lm-eval**: a `samples_<task>_<timestamp>.jsonl` file, a model's directory, or the whole
|
|
186
|
+
`--output_path`. The samples file does not name its model; lm-eval writes it beside a
|
|
187
|
+
`results_<timestamp>.json` that does, and that is where the name comes from. A samples file
|
|
188
|
+
moved away from it has to be named: `my-model=path/to/samples_copa_....jsonl`. When a directory
|
|
189
|
+
holds several runs of a task, the latest is used and a note says so. Question ids are
|
|
190
|
+
`<task>-<doc_id>`, so several tasks of one model add up to one benchmark.
|
|
191
|
+
- **Inspect AI**: `.eval` (or `.json`) logs; the model is the one in the log. Epochs (`--epochs N`,
|
|
192
|
+
repeated sampling of the same input) land in the `sample` column automatically.
|
|
193
|
+
- With exactly two models in the input, `compare` needs no `--model-a`/`--model-b`: A is the first
|
|
194
|
+
one given. When the two were not scored on the same questions (a different `--limit`, a run
|
|
195
|
+
that crashed), the comparison uses the shared ones and reports how many were left out.
|
|
196
|
+
|
|
157
197
|
`--metric` (lm-eval) picks which computed metric to use as the score when a task reports more than
|
|
158
198
|
one (e.g. `acc` vs. `acc_norm`); it defaults to the first one. `--filter` (lm-eval) picks one filter
|
|
159
199
|
for a task that scores every question under several: `gsm8k_cot_self_consistency` logs each question
|
|
160
200
|
three times (`score-first`, `maj@8`, `maj@64`), and reading those as three times the questions would
|
|
161
201
|
shrink every error bar, so the import stops and asks. `--scorer` (Inspect) picks one scorer for
|
|
162
|
-
tasks with more than one.
|
|
163
|
-
the `sample` column automatically.
|
|
202
|
+
tasks with more than one.
|
|
164
203
|
|
|
165
204
|
Both adapters were built and tested against real, unedited output — not from memory: **lm-eval
|
|
166
|
-
0.4.13** (`lm_eval run --model dummy --tasks copa --limit 20 --log_samples ...`,
|
|
167
|
-
|
|
168
|
-
0.3.268** (small tasks through the built-in `mockllm/model` provider: single
|
|
169
|
-
a scorer with named values). The exact log files are committed as test
|
|
170
|
-
(`tests/fixtures/samples_*.jsonl`, `tests/fixtures/
|
|
171
|
-
`tests/
|
|
205
|
+
0.4.13** (`lm_eval run --model dummy --tasks copa --limit 20 --log_samples ...`, a multi-metric
|
|
206
|
+
`arc_easy` run, a three-filter `gsm8k_cot_self_consistency` run, and the two-model output directory
|
|
207
|
+
above) and **inspect-ai 0.3.268** (small tasks through the built-in `mockllm/model` provider: single
|
|
208
|
+
epoch, two epochs, and a scorer with named values). The exact log files are committed as test
|
|
209
|
+
fixtures (`tests/fixtures/samples_*.jsonl`, `tests/fixtures/lm_eval_output/`,
|
|
210
|
+
`tests/fixtures/inspect_*.eval`) and re-parsed in `tests/test_adapters.py` and
|
|
211
|
+
`tests/test_inputs.py` on every run. The Inspect adapter reads logs with Inspect's own
|
|
172
212
|
`inspect_ai.log.read_eval_log` and `inspect_ai.scorer.value_to_float` rather than hand-parsing its
|
|
173
213
|
binary `.eval` format, and needs the `inspect` extra:
|
|
174
214
|
`pip install "errorbars[inspect]"`. The lm-eval
|
|
@@ -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.
|
|
35
|
+
version = "0.2.0"
|
|
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"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""errorbars: statistical rigor for LLM eval results."""
|
|
2
2
|
|
|
3
|
+
from errorbars.inputs import load_inputs
|
|
3
4
|
from errorbars.stats import (
|
|
4
5
|
ClusterDiagnostics,
|
|
5
6
|
MeanEstimate,
|
|
@@ -12,10 +13,11 @@ from errorbars.stats import (
|
|
|
12
13
|
within_between_variance,
|
|
13
14
|
)
|
|
14
15
|
|
|
15
|
-
__version__ = "0.
|
|
16
|
+
__version__ = "0.2.0"
|
|
16
17
|
|
|
17
18
|
__all__ = [
|
|
18
19
|
"__version__",
|
|
20
|
+
"load_inputs",
|
|
19
21
|
"MeanEstimate",
|
|
20
22
|
"ClusterDiagnostics",
|
|
21
23
|
"mean_ci_clt",
|
|
@@ -20,10 +20,16 @@ Each line of a `--log_samples` file is a JSON object with (at least)::
|
|
|
20
20
|
|
|
21
21
|
``metrics`` names which top-level keys on the record hold computed scores
|
|
22
22
|
(a multiple-choice task can report more than one, e.g. ``acc`` and
|
|
23
|
-
``acc_norm``).
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
``
|
|
23
|
+
``acc_norm``).
|
|
24
|
+
|
|
25
|
+
The samples file has no model name in it. lm-eval writes it next to a
|
|
26
|
+
``results_<same timestamp>.json`` whose ``model_name`` is the model
|
|
27
|
+
(``sshleifer/tiny-gpt2`` for ``--model hf --model_args
|
|
28
|
+
pretrained=sshleifer/tiny-gpt2``; checked against two such runs, committed
|
|
29
|
+
under ``tests/fixtures/lm_eval_output/``), in a directory named after it
|
|
30
|
+
(``sshleifer__tiny-gpt2``). :func:`infer_model_name` reads that file. For the
|
|
31
|
+
``dummy`` model the name is a random id, and a samples file moved away from
|
|
32
|
+
its results file has none: then the caller supplies one.
|
|
27
33
|
|
|
28
34
|
A task with several filters (``gsm8k_cot_self_consistency`` scores each
|
|
29
35
|
question under ``score-first``, ``maj@8`` and ``maj@64``) logs one record per
|
|
@@ -39,11 +45,12 @@ from pathlib import Path
|
|
|
39
45
|
|
|
40
46
|
from errorbars.io import EvalData, _coerce_score
|
|
41
47
|
|
|
42
|
-
__all__ = ["load_lm_eval_samples"]
|
|
48
|
+
__all__ = ["load_lm_eval_samples", "infer_model_name", "samples_file_parts", "looks_like_samples"]
|
|
43
49
|
|
|
44
50
|
# lm-eval's own convention (loggers/evaluation_tracker.py): samples files are
|
|
45
51
|
# named "samples_<task>_<ISO timestamp>.jsonl". Searched rather than anchored
|
|
46
52
|
# to the start so a path prefix (or a renamed-but-suffixed fixture) still matches.
|
|
53
|
+
_SAMPLES_RE = re.compile(r"samples_(?P<task>.+?)_(?P<stamp>\d{4}-\d{2}-\d{2}T[0-9.\-]+?)\.jsonl$")
|
|
47
54
|
_TASK_NAME_RE = re.compile(r"samples_(?P<task>.+?)_\d{4}-\d{2}-\d{2}T")
|
|
48
55
|
|
|
49
56
|
|
|
@@ -52,16 +59,61 @@ def _infer_task_name(path: Path) -> str | None:
|
|
|
52
59
|
return m.group("task") if m else None
|
|
53
60
|
|
|
54
61
|
|
|
62
|
+
def samples_file_parts(path: str | Path) -> tuple[str, str] | None:
|
|
63
|
+
"""``(task, timestamp)`` from a ``samples_<task>_<timestamp>.jsonl`` name, else ``None``."""
|
|
64
|
+
m = _SAMPLES_RE.search(Path(path).name)
|
|
65
|
+
return (m.group("task"), m.group("stamp")) if m else None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def looks_like_samples(record: object) -> bool:
|
|
69
|
+
"""True for a record of a ``--log_samples`` file, as opposed to a row of errorbars' own
|
|
70
|
+
JSONL: it carries the document's id and the names of its computed metrics."""
|
|
71
|
+
return isinstance(record, dict) and "doc_id" in record and isinstance(record.get("metrics"), list)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def infer_model_name(path: str | Path) -> str | None:
|
|
75
|
+
"""The model that wrote a samples file, from the ``results_*.json`` lm-eval put beside it.
|
|
76
|
+
|
|
77
|
+
The results file of the same run (same timestamp) is used; a directory holding exactly
|
|
78
|
+
one results file is taken at its word too. ``None`` when there is none, when several
|
|
79
|
+
could be meant, or when it names no model.
|
|
80
|
+
"""
|
|
81
|
+
path = Path(path)
|
|
82
|
+
parts = samples_file_parts(path)
|
|
83
|
+
candidates: list[Path] = []
|
|
84
|
+
if parts is not None:
|
|
85
|
+
same_run = path.with_name(f"results_{parts[1]}.json")
|
|
86
|
+
if same_run.is_file():
|
|
87
|
+
candidates = [same_run]
|
|
88
|
+
if not candidates:
|
|
89
|
+
others = sorted(path.parent.glob("results_*.json"))
|
|
90
|
+
if len(others) == 1:
|
|
91
|
+
candidates = others
|
|
92
|
+
for candidate in candidates:
|
|
93
|
+
try:
|
|
94
|
+
with open(candidate, encoding="utf-8") as f:
|
|
95
|
+
results = json.load(f)
|
|
96
|
+
except (OSError, ValueError):
|
|
97
|
+
continue
|
|
98
|
+
name = results.get("model_name") if isinstance(results, dict) else None
|
|
99
|
+
if isinstance(name, str) and name.strip():
|
|
100
|
+
return name
|
|
101
|
+
return None
|
|
102
|
+
|
|
103
|
+
|
|
55
104
|
def load_lm_eval_samples(
|
|
56
|
-
path: str | Path,
|
|
105
|
+
path: str | Path,
|
|
106
|
+
model: str | None = None,
|
|
107
|
+
metric: str | None = None,
|
|
108
|
+
filter_name: str | None = None,
|
|
57
109
|
) -> EvalData:
|
|
58
110
|
"""Load an lm-evaluation-harness ``--log_samples`` JSONL file.
|
|
59
111
|
|
|
60
112
|
Args:
|
|
61
113
|
path: path to a ``samples_<task>_<timestamp>.jsonl`` file.
|
|
62
|
-
model: model name to record
|
|
63
|
-
|
|
64
|
-
|
|
114
|
+
model: model name to record. Defaults to the one in the
|
|
115
|
+
``results_*.json`` lm-eval wrote beside the samples file (see
|
|
116
|
+
:func:`infer_model_name`); required when there is none.
|
|
65
117
|
metric: which computed metric to use as the score, e.g. ``"acc"``
|
|
66
118
|
or ``"acc_norm"``. Defaults to the first name in each record's
|
|
67
119
|
``metrics`` list.
|
|
@@ -75,6 +127,13 @@ def load_lm_eval_samples(
|
|
|
75
127
|
"""
|
|
76
128
|
path = Path(path)
|
|
77
129
|
task_name = _infer_task_name(path)
|
|
130
|
+
if model is None:
|
|
131
|
+
model = infer_model_name(path)
|
|
132
|
+
if model is None:
|
|
133
|
+
raise ValueError(
|
|
134
|
+
f"{path}: can't tell which model wrote this (no results_*.json beside it names one); "
|
|
135
|
+
"pass model=... (on the command line: --model NAME, or NAME=PATH)"
|
|
136
|
+
)
|
|
78
137
|
|
|
79
138
|
records: list[tuple[int, dict[str, object]]] = []
|
|
80
139
|
filters: dict[str, None] = {} # in order of first appearance
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Command-line interface: ``errorbars summarize|compare|leaderboard|power``."""
|
|
1
|
+
"""Command-line interface: ``errorbars summarize|compare|leaderboard|power|import``."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -10,7 +10,8 @@ from typing import Any
|
|
|
10
10
|
|
|
11
11
|
from errorbars import __version__
|
|
12
12
|
from errorbars.compare import paired_compare
|
|
13
|
-
from errorbars.
|
|
13
|
+
from errorbars.inputs import load_inputs
|
|
14
|
+
from errorbars.io import ColumnMap, EvalData, write_csv
|
|
14
15
|
from errorbars.leaderboard import build_leaderboard
|
|
15
16
|
from errorbars.plot import forest_plot_svg
|
|
16
17
|
from errorbars.power import minimum_detectable_effect, questions_needed
|
|
@@ -33,21 +34,52 @@ def _require_models(data: EvalData, *names: str) -> None:
|
|
|
33
34
|
raise SystemExit(f"error: no model {name!r} in the data (models: {listed})")
|
|
34
35
|
|
|
35
36
|
|
|
36
|
-
def _load(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
def _load(args: argparse.Namespace, model: str | None = None) -> EvalData:
|
|
38
|
+
"""The data a command was pointed at: every FILE, read as what it is and put together."""
|
|
39
|
+
try:
|
|
40
|
+
loaded = load_inputs(
|
|
41
|
+
args.file,
|
|
42
|
+
_columns_from(args),
|
|
43
|
+
model=model,
|
|
44
|
+
metric=args.metric,
|
|
45
|
+
filter_name=args.filter,
|
|
46
|
+
scorer=args.scorer,
|
|
47
|
+
)
|
|
48
|
+
except ImportError as exc:
|
|
49
|
+
raise SystemExit(f"error: {exc}") from exc
|
|
50
|
+
for note in loaded.notes:
|
|
51
|
+
print(f"note: {note}", file=sys.stderr)
|
|
52
|
+
return loaded.data
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
_FILE_HELP = (
|
|
56
|
+
"one or more files or directories: errorbars CSV/JSONL, lm-eval samples_*.jsonl, "
|
|
57
|
+
"Inspect .eval logs. NAME=PATH names a harness log's model"
|
|
58
|
+
)
|
|
43
59
|
|
|
44
60
|
|
|
45
|
-
def
|
|
61
|
+
def _input_args(sp: argparse.ArgumentParser) -> None:
|
|
62
|
+
sp.add_argument("file", nargs="+", metavar="FILE", help=_FILE_HELP)
|
|
46
63
|
sp.add_argument("--question-col", default="question_id")
|
|
47
64
|
sp.add_argument("--model-col", default="model")
|
|
48
65
|
sp.add_argument("--score-col", default="score")
|
|
49
66
|
sp.add_argument("--cluster-col", default="cluster_id")
|
|
50
67
|
sp.add_argument("--sample-col", default="sample")
|
|
68
|
+
_harness_args(sp)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _harness_args(sp: argparse.ArgumentParser) -> None:
|
|
72
|
+
sp.add_argument(
|
|
73
|
+
"--metric", default=None, help="lm-eval metric to use as the score (default: first available)"
|
|
74
|
+
)
|
|
75
|
+
sp.add_argument(
|
|
76
|
+
"--filter",
|
|
77
|
+
default=None,
|
|
78
|
+
help="lm-eval filter to use, for a task that scores each question under several (e.g. maj@8)",
|
|
79
|
+
)
|
|
80
|
+
sp.add_argument(
|
|
81
|
+
"--scorer", default=None, help="Inspect scorer to use (default: the only one, if unambiguous)"
|
|
82
|
+
)
|
|
51
83
|
|
|
52
84
|
|
|
53
85
|
def _columns_from(args: argparse.Namespace) -> ColumnMap:
|
|
@@ -70,10 +102,26 @@ def _console() -> Console:
|
|
|
70
102
|
return Console()
|
|
71
103
|
|
|
72
104
|
|
|
105
|
+
def _has_clusters(data: EvalData) -> bool:
|
|
106
|
+
"""True when the data groups questions: some cluster id that isn't its question's own id,
|
|
107
|
+
which is what a file without a cluster column is filled with."""
|
|
108
|
+
if not data.cluster_id:
|
|
109
|
+
return False
|
|
110
|
+
return any(c != q for c, q in zip(data.cluster_id, data.question_id, strict=True))
|
|
111
|
+
|
|
112
|
+
|
|
73
113
|
def cmd_summarize(args: argparse.Namespace) -> None:
|
|
74
|
-
data = _load(args
|
|
114
|
+
data = _load(args)
|
|
75
115
|
if args.model:
|
|
76
116
|
_require_models(data, args.model)
|
|
117
|
+
elif len(data.models()) > 1:
|
|
118
|
+
# Pooled, four models' answers to 200 questions would be summarized as 800 questions.
|
|
119
|
+
models = data.models()
|
|
120
|
+
listed = ", ".join(repr(m) for m in models[:10]) + (", ..." if len(models) > 10 else "")
|
|
121
|
+
raise SystemExit(
|
|
122
|
+
f"error: the data has {len(models)} models ({listed}); summarize one with --model, "
|
|
123
|
+
"or rank them all with `errorbars leaderboard`"
|
|
124
|
+
)
|
|
77
125
|
sub = data.filter_model(args.model) if args.model else data
|
|
78
126
|
if not sub.score:
|
|
79
127
|
raise SystemExit(f"error: no rows for model {args.model!r}" if args.model else "error: empty data")
|
|
@@ -90,11 +138,12 @@ def cmd_summarize(args: argparse.Namespace) -> None:
|
|
|
90
138
|
est = mean_ci_clt(scores, confidence=args.confidence)
|
|
91
139
|
|
|
92
140
|
result: dict[str, Any] = est.as_dict()
|
|
93
|
-
|
|
141
|
+
models = sub.models()
|
|
142
|
+
result["model"] = args.model or (models[0] if len(models) == 1 else "(all)")
|
|
94
143
|
result["is_binary"] = binary
|
|
95
144
|
|
|
96
145
|
cluster_info = None
|
|
97
|
-
if sub.cluster_id and len(set(sub.cluster_id)) > 1:
|
|
146
|
+
if _has_clusters(sub) and sub.cluster_id and len(set(sub.cluster_id)) > 1:
|
|
98
147
|
from errorbars.stats import (
|
|
99
148
|
cluster_robust_se,
|
|
100
149
|
design_effect,
|
|
@@ -163,15 +212,36 @@ def cmd_summarize(args: argparse.Namespace) -> None:
|
|
|
163
212
|
console.print(wt)
|
|
164
213
|
|
|
165
214
|
|
|
215
|
+
def _models_to_compare(data: EvalData, model_a: str | None, model_b: str | None) -> tuple[str, str]:
|
|
216
|
+
"""The two models of a comparison: the ones named, or the only two there are, in the
|
|
217
|
+
order the input gave them."""
|
|
218
|
+
if model_a is None and model_b is None:
|
|
219
|
+
models = data.models()
|
|
220
|
+
if len(models) == 2:
|
|
221
|
+
return models[0], models[1]
|
|
222
|
+
listed = ", ".join(repr(m) for m in models[:10]) + (", ..." if len(models) > 10 else "")
|
|
223
|
+
raise SystemExit(
|
|
224
|
+
f"error: the data has {len(models)} model{'s' if len(models) != 1 else ''} ({listed}); "
|
|
225
|
+
"a comparison needs two (pick them with --model-a and --model-b)"
|
|
226
|
+
)
|
|
227
|
+
if model_a is None or model_b is None:
|
|
228
|
+
raise SystemExit("error: pass both --model-a and --model-b, or neither when there are two models")
|
|
229
|
+
_require_models(data, model_a, model_b)
|
|
230
|
+
return model_a, model_b
|
|
231
|
+
|
|
232
|
+
|
|
166
233
|
def cmd_compare(args: argparse.Namespace) -> None:
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
_require_models(data, args.model_a, args.model_b)
|
|
234
|
+
data = _load(args)
|
|
235
|
+
args.model_a, args.model_b = _models_to_compare(data, args.model_a, args.model_b)
|
|
170
236
|
a = data.filter_model(args.model_a).scores_by_question()
|
|
171
237
|
b = data.filter_model(args.model_b).scores_by_question()
|
|
172
238
|
common = sorted(set(a) & set(b))
|
|
239
|
+
only_a, only_b = len(set(a) - set(b)), len(set(b) - set(a))
|
|
173
240
|
if len(common) < 2:
|
|
174
|
-
raise SystemExit(
|
|
241
|
+
raise SystemExit(
|
|
242
|
+
"error: fewer than 2 shared question_ids between the two models "
|
|
243
|
+
f"({len(a)} questions for {args.model_a!r}, {len(b)} for {args.model_b!r}, {len(common)} in both)"
|
|
244
|
+
)
|
|
175
245
|
sa = [a[q] for q in common]
|
|
176
246
|
sb = [b[q] for q in common]
|
|
177
247
|
clusters = None
|
|
@@ -181,7 +251,15 @@ def cmd_compare(args: argparse.Namespace) -> None:
|
|
|
181
251
|
comp = paired_compare(sa, sb, clusters=clusters, confidence=args.confidence)
|
|
182
252
|
|
|
183
253
|
if args.json:
|
|
184
|
-
_print_json(
|
|
254
|
+
_print_json(
|
|
255
|
+
{
|
|
256
|
+
"model_a": args.model_a,
|
|
257
|
+
"model_b": args.model_b,
|
|
258
|
+
**comp.as_dict(),
|
|
259
|
+
"n_only_a": only_a,
|
|
260
|
+
"n_only_b": only_b,
|
|
261
|
+
}
|
|
262
|
+
)
|
|
185
263
|
return
|
|
186
264
|
|
|
187
265
|
console = _console()
|
|
@@ -189,6 +267,9 @@ def cmd_compare(args: argparse.Namespace) -> None:
|
|
|
189
267
|
table.add_column("metric")
|
|
190
268
|
table.add_column("value", justify="right")
|
|
191
269
|
table.add_row("n (shared questions)", str(comp.n))
|
|
270
|
+
if only_a or only_b:
|
|
271
|
+
# The two runs did not cover the same questions (a different --limit, a crashed run).
|
|
272
|
+
table.add_row("questions left out (only A / only B)", f"{only_a} / {only_b}")
|
|
192
273
|
table.add_row(f"mean({args.model_a})", f"{comp.mean_a:.4f}")
|
|
193
274
|
table.add_row(f"mean({args.model_b})", f"{comp.mean_b:.4f}")
|
|
194
275
|
table.add_row("mean diff (A - B)", f"{comp.mean_diff:.4f}")
|
|
@@ -213,8 +294,9 @@ def cmd_compare(args: argparse.Namespace) -> None:
|
|
|
213
294
|
|
|
214
295
|
|
|
215
296
|
def cmd_leaderboard(args: argparse.Namespace) -> None:
|
|
216
|
-
data = _load(args
|
|
297
|
+
data = _load(args)
|
|
217
298
|
lb = build_leaderboard(data, confidence=args.confidence, alpha=args.alpha)
|
|
299
|
+
question_sets = {frozenset(data.filter_model(m).question_id) for m in data.models()}
|
|
218
300
|
|
|
219
301
|
if args.plot:
|
|
220
302
|
svg = forest_plot_svg(lb, title=args.plot_title)
|
|
@@ -274,6 +356,11 @@ def cmd_leaderboard(args: argparse.Namespace) -> None:
|
|
|
274
356
|
"[dim]'p (used, Holm)' is the cluster-robust paired p-value (when clusters are "
|
|
275
357
|
"present) after Holm correction across all pairs; otherwise the unclustered paired p-value.[/dim]"
|
|
276
358
|
)
|
|
359
|
+
if len(question_sets) > 1:
|
|
360
|
+
console.print(
|
|
361
|
+
"[yellow]The models were not scored on the same questions. Each mean is over that "
|
|
362
|
+
"model's own questions; each paired test uses the questions its two models share.[/yellow]"
|
|
363
|
+
)
|
|
277
364
|
|
|
278
365
|
|
|
279
366
|
def cmd_power(args: argparse.Namespace) -> None:
|
|
@@ -321,21 +408,11 @@ def cmd_power(args: argparse.Namespace) -> None:
|
|
|
321
408
|
|
|
322
409
|
|
|
323
410
|
def cmd_import(args: argparse.Namespace) -> None:
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
data = load_lm_eval_samples(args.file, model=args.model, metric=args.metric, filter_name=args.filter)
|
|
330
|
-
elif args.adapter == "inspect":
|
|
331
|
-
try:
|
|
332
|
-
from errorbars.adapters.inspect_ai import load_inspect_log
|
|
333
|
-
except ImportError as exc:
|
|
334
|
-
raise SystemExit(f"error: {exc}") from exc
|
|
335
|
-
|
|
336
|
-
data = load_inspect_log(args.file, scorer=args.scorer)
|
|
337
|
-
else: # pragma: no cover - argparse `choices` already prevents this
|
|
338
|
-
raise SystemExit(f"error: unknown adapter {args.adapter!r}")
|
|
411
|
+
# The adapter word is kept for the commands people already have; what each file is, is
|
|
412
|
+
# read from the file.
|
|
413
|
+
args.question_col, args.model_col, args.score_col = "question_id", "model", "score"
|
|
414
|
+
args.cluster_col, args.sample_col = "cluster_id", "sample"
|
|
415
|
+
data = _load(args, model=args.model)
|
|
339
416
|
|
|
340
417
|
write_csv(data, args.output)
|
|
341
418
|
n_models = len(data.models())
|
|
@@ -348,32 +425,31 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
348
425
|
sub = parser.add_subparsers(dest="command", required=True)
|
|
349
426
|
|
|
350
427
|
p_sum = sub.add_parser("summarize", help="mean, SE, and CI for one model")
|
|
351
|
-
p_sum.add_argument("file")
|
|
352
428
|
p_sum.add_argument("--model", default=None, help="filter to this model (default: use all rows)")
|
|
353
429
|
p_sum.add_argument("--confidence", type=float, default=0.95)
|
|
354
430
|
p_sum.add_argument("--ci", choices=["auto", "clt", "wilson", "bootstrap"], default="auto")
|
|
355
431
|
p_sum.add_argument("--seed", type=int, default=0, help="bootstrap RNG seed")
|
|
356
432
|
p_sum.add_argument("--json", action="store_true")
|
|
357
|
-
|
|
433
|
+
_input_args(p_sum)
|
|
358
434
|
p_sum.set_defaults(func=cmd_summarize)
|
|
359
435
|
|
|
360
436
|
p_cmp = sub.add_parser("compare", help="paired comparison of two models")
|
|
361
|
-
p_cmp.add_argument(
|
|
362
|
-
|
|
363
|
-
|
|
437
|
+
p_cmp.add_argument(
|
|
438
|
+
"--model-a", default=None, help="default: the first of the two models in the input"
|
|
439
|
+
)
|
|
440
|
+
p_cmp.add_argument("--model-b", default=None, help="default: the second")
|
|
364
441
|
p_cmp.add_argument("--confidence", type=float, default=0.95)
|
|
365
442
|
p_cmp.add_argument("--json", action="store_true")
|
|
366
|
-
|
|
443
|
+
_input_args(p_cmp)
|
|
367
444
|
p_cmp.set_defaults(func=cmd_compare)
|
|
368
445
|
|
|
369
446
|
p_lb = sub.add_parser("leaderboard", help="rank all models with pairwise tests")
|
|
370
|
-
p_lb.add_argument("file")
|
|
371
447
|
p_lb.add_argument("--confidence", type=float, default=0.95)
|
|
372
448
|
p_lb.add_argument("--alpha", type=float, default=0.05)
|
|
373
449
|
p_lb.add_argument("--plot", default=None, help="write an SVG forest plot to this path")
|
|
374
450
|
p_lb.add_argument("--plot-title", default=None)
|
|
375
451
|
p_lb.add_argument("--json", action="store_true")
|
|
376
|
-
|
|
452
|
+
_input_args(p_lb)
|
|
377
453
|
p_lb.set_defaults(func=cmd_leaderboard)
|
|
378
454
|
|
|
379
455
|
p_pow = sub.add_parser("power", help="sample-size / minimum-detectable-effect planning")
|
|
@@ -397,22 +473,14 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
397
473
|
"import", help="convert an lm-evaluation-harness or Inspect AI log to the canonical CSV"
|
|
398
474
|
)
|
|
399
475
|
p_imp.add_argument("adapter", choices=["lm-eval", "inspect"])
|
|
400
|
-
p_imp.add_argument("file",
|
|
476
|
+
p_imp.add_argument("file", nargs="+", metavar="FILE", help=_FILE_HELP)
|
|
401
477
|
p_imp.add_argument("-o", "--output", required=True, help="path to write the canonical CSV to")
|
|
402
478
|
p_imp.add_argument(
|
|
403
|
-
"--model",
|
|
404
|
-
)
|
|
405
|
-
p_imp.add_argument(
|
|
406
|
-
"--metric", default=None, help="lm-eval metric to use as the score (default: first available)"
|
|
407
|
-
)
|
|
408
|
-
p_imp.add_argument(
|
|
409
|
-
"--filter",
|
|
479
|
+
"--model",
|
|
410
480
|
default=None,
|
|
411
|
-
help="
|
|
412
|
-
)
|
|
413
|
-
p_imp.add_argument(
|
|
414
|
-
"--scorer", default=None, help="Inspect scorer to use (default: the only one, if unambiguous)"
|
|
481
|
+
help="model name for every log given (default: the one each log names; NAME=PATH names one)",
|
|
415
482
|
)
|
|
483
|
+
_harness_args(p_imp)
|
|
416
484
|
p_imp.set_defaults(func=cmd_import)
|
|
417
485
|
|
|
418
486
|
return parser
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""Reading results the way they are left on disk: several files, in several formats.
|
|
2
|
+
|
|
3
|
+
An eval harness writes one log per model and per task. lm-evaluation-harness puts
|
|
4
|
+
``samples_<task>_<timestamp>.jsonl`` files in a directory per model; Inspect AI writes one
|
|
5
|
+
``.eval`` log per run. Comparing two models therefore starts from two files at least, and
|
|
6
|
+
the question this package answers is always about more than one of them. :func:`load_inputs`
|
|
7
|
+
takes them as they are:
|
|
8
|
+
|
|
9
|
+
- a CSV or JSONL file in errorbars' own long format;
|
|
10
|
+
- an lm-eval samples file, recognized by its records;
|
|
11
|
+
- an Inspect ``.eval`` (or ``.json``) log;
|
|
12
|
+
- a directory, searched for lm-eval samples files and Inspect logs.
|
|
13
|
+
|
|
14
|
+
and returns their rows as one :class:`~errorbars.io.EvalData`.
|
|
15
|
+
|
|
16
|
+
A harness log can be given as ``NAME=PATH`` to name its model: to tell two runs of one
|
|
17
|
+
model apart (``greedy=run1.eval sampled=run2.eval``), or because an lm-eval samples file
|
|
18
|
+
that was moved away from its ``results_*.json`` no longer says which model wrote it.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import errno
|
|
24
|
+
import json
|
|
25
|
+
import os
|
|
26
|
+
from collections.abc import Sequence
|
|
27
|
+
from dataclasses import dataclass, field
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
from errorbars.adapters.lm_eval import (
|
|
31
|
+
load_lm_eval_samples,
|
|
32
|
+
looks_like_samples,
|
|
33
|
+
samples_file_parts,
|
|
34
|
+
)
|
|
35
|
+
from errorbars.io import ColumnMap, EvalData, concat, load_csv, load_jsonl
|
|
36
|
+
|
|
37
|
+
__all__ = ["Loaded", "load_inputs", "split_spec"]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass
|
|
41
|
+
class Loaded:
|
|
42
|
+
"""What :func:`load_inputs` read, and what it chose not to."""
|
|
43
|
+
|
|
44
|
+
data: EvalData
|
|
45
|
+
#: The files the rows came from, in the order they were read.
|
|
46
|
+
files: list[Path] = field(default_factory=list)
|
|
47
|
+
#: Things the caller should tell the user: an older run that was passed over.
|
|
48
|
+
notes: list[str] = field(default_factory=list)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def split_spec(spec: str) -> tuple[str | None, Path]:
|
|
52
|
+
"""``NAME=PATH`` as ``(NAME, PATH)``, or a plain path as ``(None, PATH)``.
|
|
53
|
+
|
|
54
|
+
A path that exists is a path, whatever characters it holds, so a file name with ``=`` in
|
|
55
|
+
it is never cut in two.
|
|
56
|
+
"""
|
|
57
|
+
if os.path.exists(spec):
|
|
58
|
+
return None, Path(spec)
|
|
59
|
+
name, sep, rest = spec.partition("=")
|
|
60
|
+
if sep and name and os.path.exists(rest):
|
|
61
|
+
return name, Path(rest)
|
|
62
|
+
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), spec)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _first_record(path: Path) -> object:
|
|
66
|
+
with open(path, encoding="utf-8") as f:
|
|
67
|
+
for line in f:
|
|
68
|
+
line = line.strip()
|
|
69
|
+
if line:
|
|
70
|
+
try:
|
|
71
|
+
return json.loads(line)
|
|
72
|
+
except json.JSONDecodeError:
|
|
73
|
+
return None
|
|
74
|
+
return None
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _kind(path: Path) -> str:
|
|
78
|
+
suffix = path.suffix.lower()
|
|
79
|
+
if suffix == ".csv":
|
|
80
|
+
return "csv"
|
|
81
|
+
if suffix in (".eval", ".json"):
|
|
82
|
+
return "inspect"
|
|
83
|
+
if suffix in (".jsonl", ".ndjson"):
|
|
84
|
+
return "lm-eval" if looks_like_samples(_first_record(path)) else "jsonl"
|
|
85
|
+
raise ValueError(
|
|
86
|
+
f"{path}: unrecognized file extension {path.suffix!r} "
|
|
87
|
+
"(use .csv or .jsonl, an lm-eval samples_*.jsonl, or an Inspect .eval log)"
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _expand_directory(directory: Path, notes: list[str]) -> list[Path]:
|
|
92
|
+
"""The logs under a directory: every Inspect log, and the latest lm-eval samples file
|
|
93
|
+
per task in each sub-directory (lm-eval adds a timestamped file on every re-run)."""
|
|
94
|
+
samples = sorted(directory.rglob("samples_*.jsonl"))
|
|
95
|
+
logs = sorted(directory.rglob("*.eval"))
|
|
96
|
+
if not samples and not logs:
|
|
97
|
+
raise ValueError(
|
|
98
|
+
f"{directory}: no lm-eval samples_*.jsonl files or Inspect .eval logs in this directory"
|
|
99
|
+
)
|
|
100
|
+
latest: dict[tuple[Path, str], Path] = {}
|
|
101
|
+
runs: dict[tuple[Path, str], int] = {}
|
|
102
|
+
for path in samples:
|
|
103
|
+
parts = samples_file_parts(path)
|
|
104
|
+
key = (path.parent, parts[0] if parts else path.name)
|
|
105
|
+
runs[key] = runs.get(key, 0) + 1
|
|
106
|
+
# ISO timestamps sort as text; `samples` is sorted, so the last one seen is the latest.
|
|
107
|
+
latest[key] = path
|
|
108
|
+
for key, count in runs.items():
|
|
109
|
+
if count > 1:
|
|
110
|
+
notes.append(
|
|
111
|
+
f"{key[0]}: {count} runs of {key[1]}; using the latest ({latest[key].name})"
|
|
112
|
+
)
|
|
113
|
+
return sorted(latest.values()) + logs
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _load_one(
|
|
117
|
+
path: Path,
|
|
118
|
+
name: str | None,
|
|
119
|
+
model: str | None,
|
|
120
|
+
columns: ColumnMap,
|
|
121
|
+
metric: str | None,
|
|
122
|
+
filter_name: str | None,
|
|
123
|
+
scorer: str | None,
|
|
124
|
+
) -> EvalData:
|
|
125
|
+
"""One file. ``name`` is the NAME of a NAME=PATH given for it; ``model`` the name given
|
|
126
|
+
for every harness log."""
|
|
127
|
+
kind = _kind(path)
|
|
128
|
+
if kind in ("csv", "jsonl"):
|
|
129
|
+
if name is not None:
|
|
130
|
+
raise ValueError(
|
|
131
|
+
f"{path}: this file names its models in its {columns.model!r} column; "
|
|
132
|
+
f"NAME=PATH ({name}=...) is for a harness log, which holds one model"
|
|
133
|
+
)
|
|
134
|
+
return load_csv(path, columns) if kind == "csv" else load_jsonl(path, columns)
|
|
135
|
+
if kind == "lm-eval":
|
|
136
|
+
return load_lm_eval_samples(
|
|
137
|
+
path, model=name or model, metric=metric, filter_name=filter_name
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
from errorbars.adapters.inspect_ai import load_inspect_log
|
|
141
|
+
|
|
142
|
+
data = load_inspect_log(path, scorer=scorer)
|
|
143
|
+
if name or model:
|
|
144
|
+
data.model = [str(name or model)] * len(data)
|
|
145
|
+
return data
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def load_inputs(
|
|
149
|
+
specs: Sequence[str | Path],
|
|
150
|
+
columns: ColumnMap | None = None,
|
|
151
|
+
*,
|
|
152
|
+
model: str | None = None,
|
|
153
|
+
metric: str | None = None,
|
|
154
|
+
filter_name: str | None = None,
|
|
155
|
+
scorer: str | None = None,
|
|
156
|
+
) -> Loaded:
|
|
157
|
+
"""Load one or more files or directories (each optionally as ``NAME=PATH``) as one dataset.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
specs: paths, or ``NAME=PATH`` strings naming a harness log's model.
|
|
161
|
+
columns: column names, for files in errorbars' own format.
|
|
162
|
+
model: a model name for every harness log that isn't given one as ``NAME=PATH``.
|
|
163
|
+
metric: lm-eval metric to use as the score (default: each record's first).
|
|
164
|
+
filter_name: lm-eval filter to use, for a task scored under several.
|
|
165
|
+
scorer: Inspect scorer to use, for a task with more than one.
|
|
166
|
+
"""
|
|
167
|
+
columns = columns or ColumnMap()
|
|
168
|
+
if not specs:
|
|
169
|
+
raise ValueError("no input files given")
|
|
170
|
+
notes: list[str] = []
|
|
171
|
+
files: list[Path] = []
|
|
172
|
+
parts: list[tuple[str, EvalData]] = []
|
|
173
|
+
for spec in specs:
|
|
174
|
+
name, path = split_spec(str(spec))
|
|
175
|
+
paths = _expand_directory(path, notes) if path.is_dir() else [path]
|
|
176
|
+
for one in paths:
|
|
177
|
+
data = _load_one(one, name, model, columns, metric, filter_name, scorer)
|
|
178
|
+
files.append(one)
|
|
179
|
+
parts.append((str(one), data))
|
|
180
|
+
return Loaded(data=concat(parts), files=files, notes=notes)
|
|
@@ -16,7 +16,15 @@ from dataclasses import dataclass, field
|
|
|
16
16
|
from pathlib import Path
|
|
17
17
|
from typing import Any
|
|
18
18
|
|
|
19
|
-
__all__ = [
|
|
19
|
+
__all__ = [
|
|
20
|
+
"EvalData",
|
|
21
|
+
"ColumnMap",
|
|
22
|
+
"concat",
|
|
23
|
+
"load_csv",
|
|
24
|
+
"load_jsonl",
|
|
25
|
+
"load_dataframe",
|
|
26
|
+
"write_csv",
|
|
27
|
+
]
|
|
20
28
|
|
|
21
29
|
|
|
22
30
|
@dataclass(frozen=True)
|
|
@@ -77,6 +85,59 @@ class EvalData:
|
|
|
77
85
|
return out
|
|
78
86
|
|
|
79
87
|
|
|
88
|
+
def concat(parts: Iterable[tuple[str, EvalData]]) -> EvalData:
|
|
89
|
+
"""Put several sources' rows together: one log per model, or one per task.
|
|
90
|
+
|
|
91
|
+
``parts`` pairs each source's name (a path, used in error messages) with its data. A
|
|
92
|
+
source without cluster ids or sample ids gets what a file without those columns gets:
|
|
93
|
+
each question its own cluster, sample ``"0"``.
|
|
94
|
+
|
|
95
|
+
The same (model, question, sample) in two sources is an error, as it is within one file:
|
|
96
|
+
counted twice, it would inflate n and shrink every standard error. It happens when a run
|
|
97
|
+
is given twice, or when two runs of one model are given without telling them apart.
|
|
98
|
+
"""
|
|
99
|
+
parts = list(parts)
|
|
100
|
+
if not parts:
|
|
101
|
+
raise ValueError("no data to combine")
|
|
102
|
+
if len(parts) == 1:
|
|
103
|
+
return parts[0][1]
|
|
104
|
+
any_clusters = any(data.cluster_id for _, data in parts)
|
|
105
|
+
any_samples = any(data.sample for _, data in parts)
|
|
106
|
+
|
|
107
|
+
question_id: list[str] = []
|
|
108
|
+
model: list[str] = []
|
|
109
|
+
score: list[float] = []
|
|
110
|
+
cluster_id: list[str] = []
|
|
111
|
+
sample: list[str] = []
|
|
112
|
+
seen: dict[tuple[str, str, str], str] = {}
|
|
113
|
+
for source, data in parts:
|
|
114
|
+
samples = data.sample or ["0"] * len(data)
|
|
115
|
+
for m, q, smp in zip(data.model, data.question_id, samples, strict=True):
|
|
116
|
+
key = (m, q, smp)
|
|
117
|
+
if key in seen:
|
|
118
|
+
raise ValueError(
|
|
119
|
+
f"{source}: model {m!r} already has a score for question {q!r} (from "
|
|
120
|
+
f"{seen[key]}). Either the same run is given twice, or these are two runs "
|
|
121
|
+
"of one model, which need different model names (NAME=PATH names a "
|
|
122
|
+
"harness log's model)"
|
|
123
|
+
)
|
|
124
|
+
seen[key] = source
|
|
125
|
+
question_id.extend(data.question_id)
|
|
126
|
+
model.extend(data.model)
|
|
127
|
+
score.extend(data.score)
|
|
128
|
+
cluster_id.extend(data.cluster_id or data.question_id)
|
|
129
|
+
sample.extend(samples)
|
|
130
|
+
|
|
131
|
+
return EvalData(
|
|
132
|
+
question_id,
|
|
133
|
+
model,
|
|
134
|
+
score,
|
|
135
|
+
cluster_id if any_clusters else None,
|
|
136
|
+
sample if any_samples else None,
|
|
137
|
+
parts[0][1].columns,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
80
141
|
_MAX_SCORE = 1e100
|
|
81
142
|
|
|
82
143
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|