errorbars 0.1.3__tar.gz → 0.2.1__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.1}/CHANGELOG.md +66 -0
- {errorbars-0.1.3 → errorbars-0.2.1}/PKG-INFO +63 -21
- {errorbars-0.1.3 → errorbars-0.2.1}/README.md +62 -20
- {errorbars-0.1.3 → errorbars-0.2.1}/pyproject.toml +1 -1
- {errorbars-0.1.3 → errorbars-0.2.1}/src/errorbars/__init__.py +3 -1
- errorbars-0.2.1/src/errorbars/_tables.py +112 -0
- {errorbars-0.1.3 → errorbars-0.2.1}/src/errorbars/adapters/inspect_ai.py +2 -1
- {errorbars-0.1.3 → errorbars-0.2.1}/src/errorbars/adapters/lm_eval.py +68 -9
- {errorbars-0.1.3 → errorbars-0.2.1}/src/errorbars/cli.py +148 -90
- errorbars-0.2.1/src/errorbars/inputs.py +180 -0
- {errorbars-0.1.3 → errorbars-0.2.1}/src/errorbars/io.py +62 -1
- {errorbars-0.1.3 → errorbars-0.2.1}/src/errorbars/stats.py +3 -2
- {errorbars-0.1.3 → errorbars-0.2.1}/.gitignore +0 -0
- {errorbars-0.1.3 → errorbars-0.2.1}/LICENSE +0 -0
- {errorbars-0.1.3 → errorbars-0.2.1}/docs/formulas.md +0 -0
- {errorbars-0.1.3 → errorbars-0.2.1}/src/errorbars/adapters/__init__.py +0 -0
- {errorbars-0.1.3 → errorbars-0.2.1}/src/errorbars/compare.py +0 -0
- {errorbars-0.1.3 → errorbars-0.2.1}/src/errorbars/leaderboard.py +0 -0
- {errorbars-0.1.3 → errorbars-0.2.1}/src/errorbars/plot.py +0 -0
- {errorbars-0.1.3 → errorbars-0.2.1}/src/errorbars/power.py +0 -0
- {errorbars-0.1.3 → errorbars-0.2.1}/src/errorbars/py.typed +0 -0
|
@@ -2,6 +2,72 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.2.1] - 2026-10-02
|
|
6
|
+
|
|
7
|
+
What the table commands print, checked the way their output is read: after `pip install
|
|
8
|
+
errorbars`, in a CI log, and with the model names harnesses produce.
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- `pip install errorbars` gives a working command line. `rich` is an extra, and without it
|
|
13
|
+
`summarize`, `compare`, `leaderboard` and `power` stopped with "rich is required for table
|
|
14
|
+
output". They print the same rows as aligned plain text now; `errorbars[cli]` still gives the
|
|
15
|
+
`rich` tables.
|
|
16
|
+
- Model names are printed whole. Written to a pipe (a CI log, a file), tables were laid out 80
|
|
17
|
+
columns wide and every cell cut to fit: lm-eval's `meta-llama__Llama-3.1-8B-Instruct` and
|
|
18
|
+
`meta-llama__Llama-3.1-70B-Instruct` were both `meta-llam…` in the pairwise table, and the
|
|
19
|
+
column headings were cut too. A pipe gets the table at its full width; a terminal too narrow
|
|
20
|
+
for it folds the names onto more lines and keeps the numbers on one.
|
|
21
|
+
- Model names are printed as they are. `rich` read `[q4_k_m]` in a name as style markup and
|
|
22
|
+
dropped it, and a name holding something like `[/b]` ended the command with a `MarkupError`
|
|
23
|
+
traceback. Nothing from the data is parsed as markup or as an emoji code any more.
|
|
24
|
+
- The message for a missing `inspect-ai` names the extra (`pip install "errorbars[inspect]"`),
|
|
25
|
+
which also carries the pins inspect-ai needs to import.
|
|
26
|
+
- The strict type check passes on Python 3.10 (an array annotation was only complete on the
|
|
27
|
+
numpy releases that need 3.11), and the test for importing an Inspect log is skipped without
|
|
28
|
+
inspect-ai, like the rest.
|
|
29
|
+
|
|
30
|
+
## [0.2.0] - 2026-10-01
|
|
31
|
+
|
|
32
|
+
A harness writes one log per model, and every command took exactly one file. Asking whether
|
|
33
|
+
model B beats model A, starting from real lm-eval output, was two `import` runs, a
|
|
34
|
+
hand-made concatenation of two CSVs, and then `compare`.
|
|
35
|
+
|
|
36
|
+
### Added
|
|
37
|
+
|
|
38
|
+
- `summarize`, `compare` and `leaderboard` take one or more files or directories and read
|
|
39
|
+
each as what it is: errorbars' CSV/JSONL, an lm-evaluation-harness `samples_*.jsonl`, or
|
|
40
|
+
an Inspect AI `.eval` log. `errorbars compare out/model-a out/model-b` is the whole
|
|
41
|
+
comparison; `errorbars leaderboard out` ranks every model under an lm-eval output
|
|
42
|
+
directory. Checked against the output directory of two real lm-eval 0.4.13 runs
|
|
43
|
+
(`--model hf`, two tiny models, COPA), committed as a fixture: the means are the
|
|
44
|
+
accuracies lm-eval reported.
|
|
45
|
+
- The model of an lm-eval samples file is read from the `results_<timestamp>.json` lm-eval
|
|
46
|
+
writes beside it (`model_name`), so `--model` is no longer required. A samples file moved
|
|
47
|
+
away from its results file has to be named, as `NAME=PATH`; the same form tells two runs of
|
|
48
|
+
one model apart (`greedy=a.eval sampled=b.eval`).
|
|
49
|
+
- A directory with several runs of one task (lm-eval adds a timestamped file on every
|
|
50
|
+
re-run) uses the latest and says so on stderr.
|
|
51
|
+
- The same model, question and sample in two inputs is refused and both files are named.
|
|
52
|
+
- `compare` with exactly two models in the input needs no `--model-a`/`--model-b`. Its
|
|
53
|
+
output says how many questions only one of the two models answered (`n_only_a`,
|
|
54
|
+
`n_only_b` in `--json`), and `leaderboard` says when the models were not scored on the same
|
|
55
|
+
questions.
|
|
56
|
+
- `import` takes several logs and directories and writes one CSV. `--metric`, `--filter`
|
|
57
|
+
and `--scorer` are available on every command that reads logs.
|
|
58
|
+
- Python: `errorbars.load_inputs`, `errorbars.io.concat`,
|
|
59
|
+
`errorbars.adapters.lm_eval.infer_model_name`.
|
|
60
|
+
|
|
61
|
+
### Fixed
|
|
62
|
+
|
|
63
|
+
- `summarize` on a file without a `cluster_id` column printed clustering diagnostics anyway,
|
|
64
|
+
with every question as its own cluster: for 4 questions, "n clusters 4" and a "clustered
|
|
65
|
+
CI" of [-0.05, 1.55]. Diagnostics now need a cluster that groups questions.
|
|
66
|
+
- `summarize` without `--model` on a file with several models pooled them: the example
|
|
67
|
+
benchmark's 4 models x 200 questions were summarized as one sample of n = 800 (SE 0.017,
|
|
68
|
+
where each model's is 0.033 to 0.035). It now asks which model, or points to `leaderboard`.
|
|
69
|
+
With one model in the data, the summary is titled with its name instead of `(all)`.
|
|
70
|
+
|
|
5
71
|
## [0.1.3] - 2026-10-01
|
|
6
72
|
|
|
7
73
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: errorbars
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
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
|
|
@@ -70,7 +70,7 @@ as a win. The full walkthrough, with every number copied from a real command, is
|
|
|
70
70
|
## Quickstart
|
|
71
71
|
|
|
72
72
|
```bash
|
|
73
|
-
pip install
|
|
73
|
+
pip install errorbars
|
|
74
74
|
errorbars power --delta 0.03 --baseline 0.5
|
|
75
75
|
```
|
|
76
76
|
|
|
@@ -101,10 +101,15 @@ errorbars leaderboard examples/data/reading_comprehension.csv
|
|
|
101
101
|
- **`power`** — number of questions needed to detect an effect δ at a given α and power, or the
|
|
102
102
|
minimum detectable effect for a given n, accounting for pairing correlation, repeated sampling,
|
|
103
103
|
and cluster design effect.
|
|
104
|
-
- **CLI** — `errorbars summarize|compare|leaderboard|power|import
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
- **CLI** — `errorbars summarize|compare|leaderboard|power|import`. Tables are plain aligned text
|
|
105
|
+
on a bare install (numpy is the only dependency) and `rich` tables with
|
|
106
|
+
`pip install "errorbars[cli]"`; either way a model name is printed whole, and a table written to
|
|
107
|
+
a pipe is as wide as it needs to be. `--json` for scripting.
|
|
108
|
+
- **Reads what harnesses write** — a harness leaves one log per model, so every command takes
|
|
109
|
+
one or more files or directories and reads each as what it is: lm-evaluation-harness
|
|
110
|
+
`--log_samples` output, Inspect AI `.eval` logs, or the CSV/JSONL format below.
|
|
111
|
+
`errorbars compare out/model-a out/model-b` is the whole comparison (see
|
|
112
|
+
[below](#reading-lm-evaluation-harness-and-inspect-ai-logs)).
|
|
108
113
|
- **Web calculator** — a static "how many eval questions do I need?" power calculator
|
|
109
114
|
([live demo](https://antonsoo.github.io/errorbars/)), whose TypeScript formulas are checked
|
|
110
115
|
against the Python ones by the test suite.
|
|
@@ -179,34 +184,71 @@ Column names are configurable (`--question-col`, `--cluster-col`, etc., or `Colu
|
|
|
179
184
|
Scores can be binary (0/1) or continuous. `cluster_id` groups correlated questions (e.g. several
|
|
180
185
|
questions per reading passage); `sample` marks repeated generations of the same question.
|
|
181
186
|
|
|
182
|
-
|
|
187
|
+
Every command takes several files (`errorbars leaderboard model-a.csv model-b.csv ...`) and puts
|
|
188
|
+
their rows together. The same model, question and sample in two files is refused, as it is within
|
|
189
|
+
one file: counted twice it would inflate n and shrink every error bar.
|
|
183
190
|
|
|
184
|
-
|
|
191
|
+
### Reading lm-evaluation-harness and Inspect AI logs
|
|
192
|
+
|
|
193
|
+
A harness writes one log per model and per task, so "is B better than A" starts from two files.
|
|
194
|
+
`summarize`, `compare` and `leaderboard` read them as they are:
|
|
185
195
|
|
|
186
196
|
```bash
|
|
187
|
-
# lm-evaluation-harness: lm_eval run --model
|
|
188
|
-
|
|
189
|
-
|
|
197
|
+
# lm-evaluation-harness: lm_eval run --model hf --model_args pretrained=<model> --tasks copa \
|
|
198
|
+
# --log_samples --output_path out (one directory per model)
|
|
199
|
+
errorbars compare out/sshleifer__tiny-gpt2 out/hf-internal-testing__tiny-random-gpt2
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
│ n (shared questions) │ 20 │
|
|
204
|
+
│ mean(sshleifer/tiny-gpt2) │ 0.6000 │
|
|
205
|
+
│ mean(hf-internal-testing/tiny-random-gpt2) │ 0.8000 │
|
|
206
|
+
│ mean diff (A - B) │ -0.2000 │
|
|
207
|
+
│ paired SE │ 0.1376 │
|
|
208
|
+
│ 95% CI │ [-0.4881, 0.0881] │
|
|
209
|
+
│ p-value │ 0.1625 │
|
|
210
|
+
│ McNemar discordant (A wrong/B right, A right/B wrong) │ 6 / 2 │
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
That is a real run, committed under `tests/fixtures/lm_eval_output/` (two tiny models, 20 COPA
|
|
214
|
+
questions). lm-eval's own table says 0.6 ± 0.11 and 0.8 ± 0.09; the paired test on the same 20
|
|
215
|
+
answers gives p = 0.16, so the 20-point gap is not evidence yet. (Rows trimmed; the command prints
|
|
216
|
+
a few more.)
|
|
190
217
|
|
|
191
|
-
|
|
192
|
-
errorbars
|
|
218
|
+
```bash
|
|
219
|
+
errorbars leaderboard out # every model under the output directory
|
|
220
|
+
errorbars compare logs/run-a.eval logs/run-b.eval # Inspect AI logs
|
|
221
|
+
errorbars compare greedy=logs/a.eval sampled=logs/b.eval # two runs of one model, told apart
|
|
222
|
+
errorbars import lm-eval out -o all.csv # or write the canonical CSV once and keep it
|
|
193
223
|
```
|
|
194
224
|
|
|
225
|
+
- **lm-eval**: a `samples_<task>_<timestamp>.jsonl` file, a model's directory, or the whole
|
|
226
|
+
`--output_path`. The samples file does not name its model; lm-eval writes it beside a
|
|
227
|
+
`results_<timestamp>.json` that does, and that is where the name comes from. A samples file
|
|
228
|
+
moved away from it has to be named: `my-model=path/to/samples_copa_....jsonl`. When a directory
|
|
229
|
+
holds several runs of a task, the latest is used and a note says so. Question ids are
|
|
230
|
+
`<task>-<doc_id>`, so several tasks of one model add up to one benchmark.
|
|
231
|
+
- **Inspect AI**: `.eval` (or `.json`) logs; the model is the one in the log. Epochs (`--epochs N`,
|
|
232
|
+
repeated sampling of the same input) land in the `sample` column automatically.
|
|
233
|
+
- With exactly two models in the input, `compare` needs no `--model-a`/`--model-b`: A is the first
|
|
234
|
+
one given. When the two were not scored on the same questions (a different `--limit`, a run
|
|
235
|
+
that crashed), the comparison uses the shared ones and reports how many were left out.
|
|
236
|
+
|
|
195
237
|
`--metric` (lm-eval) picks which computed metric to use as the score when a task reports more than
|
|
196
238
|
one (e.g. `acc` vs. `acc_norm`); it defaults to the first one. `--filter` (lm-eval) picks one filter
|
|
197
239
|
for a task that scores every question under several: `gsm8k_cot_self_consistency` logs each question
|
|
198
240
|
three times (`score-first`, `maj@8`, `maj@64`), and reading those as three times the questions would
|
|
199
241
|
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.
|
|
242
|
+
tasks with more than one.
|
|
202
243
|
|
|
203
244
|
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/
|
|
245
|
+
0.4.13** (`lm_eval run --model dummy --tasks copa --limit 20 --log_samples ...`, a multi-metric
|
|
246
|
+
`arc_easy` run, a three-filter `gsm8k_cot_self_consistency` run, and the two-model output directory
|
|
247
|
+
above) and **inspect-ai 0.3.268** (small tasks through the built-in `mockllm/model` provider: single
|
|
248
|
+
epoch, two epochs, and a scorer with named values). The exact log files are committed as test
|
|
249
|
+
fixtures (`tests/fixtures/samples_*.jsonl`, `tests/fixtures/lm_eval_output/`,
|
|
250
|
+
`tests/fixtures/inspect_*.eval`) and re-parsed in `tests/test_adapters.py` and
|
|
251
|
+
`tests/test_inputs.py` on every run. The Inspect adapter reads logs with Inspect's own
|
|
210
252
|
`inspect_ai.log.read_eval_log` and `inspect_ai.scorer.value_to_float` rather than hand-parsing its
|
|
211
253
|
binary `.eval` format, and needs the `inspect` extra:
|
|
212
254
|
`pip install "errorbars[inspect]"`. The lm-eval
|
|
@@ -32,7 +32,7 @@ as a win. The full walkthrough, with every number copied from a real command, is
|
|
|
32
32
|
## Quickstart
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
|
-
pip install
|
|
35
|
+
pip install errorbars
|
|
36
36
|
errorbars power --delta 0.03 --baseline 0.5
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -63,10 +63,15 @@ errorbars leaderboard examples/data/reading_comprehension.csv
|
|
|
63
63
|
- **`power`** — number of questions needed to detect an effect δ at a given α and power, or the
|
|
64
64
|
minimum detectable effect for a given n, accounting for pairing correlation, repeated sampling,
|
|
65
65
|
and cluster design effect.
|
|
66
|
-
- **CLI** — `errorbars summarize|compare|leaderboard|power|import
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
- **CLI** — `errorbars summarize|compare|leaderboard|power|import`. Tables are plain aligned text
|
|
67
|
+
on a bare install (numpy is the only dependency) and `rich` tables with
|
|
68
|
+
`pip install "errorbars[cli]"`; either way a model name is printed whole, and a table written to
|
|
69
|
+
a pipe is as wide as it needs to be. `--json` for scripting.
|
|
70
|
+
- **Reads what harnesses write** — a harness leaves one log per model, so every command takes
|
|
71
|
+
one or more files or directories and reads each as what it is: lm-evaluation-harness
|
|
72
|
+
`--log_samples` output, Inspect AI `.eval` logs, or the CSV/JSONL format below.
|
|
73
|
+
`errorbars compare out/model-a out/model-b` is the whole comparison (see
|
|
74
|
+
[below](#reading-lm-evaluation-harness-and-inspect-ai-logs)).
|
|
70
75
|
- **Web calculator** — a static "how many eval questions do I need?" power calculator
|
|
71
76
|
([live demo](https://antonsoo.github.io/errorbars/)), whose TypeScript formulas are checked
|
|
72
77
|
against the Python ones by the test suite.
|
|
@@ -141,34 +146,71 @@ Column names are configurable (`--question-col`, `--cluster-col`, etc., or `Colu
|
|
|
141
146
|
Scores can be binary (0/1) or continuous. `cluster_id` groups correlated questions (e.g. several
|
|
142
147
|
questions per reading passage); `sample` marks repeated generations of the same question.
|
|
143
148
|
|
|
144
|
-
|
|
149
|
+
Every command takes several files (`errorbars leaderboard model-a.csv model-b.csv ...`) and puts
|
|
150
|
+
their rows together. The same model, question and sample in two files is refused, as it is within
|
|
151
|
+
one file: counted twice it would inflate n and shrink every error bar.
|
|
145
152
|
|
|
146
|
-
|
|
153
|
+
### Reading lm-evaluation-harness and Inspect AI logs
|
|
154
|
+
|
|
155
|
+
A harness writes one log per model and per task, so "is B better than A" starts from two files.
|
|
156
|
+
`summarize`, `compare` and `leaderboard` read them as they are:
|
|
147
157
|
|
|
148
158
|
```bash
|
|
149
|
-
# lm-evaluation-harness: lm_eval run --model
|
|
150
|
-
|
|
151
|
-
|
|
159
|
+
# lm-evaluation-harness: lm_eval run --model hf --model_args pretrained=<model> --tasks copa \
|
|
160
|
+
# --log_samples --output_path out (one directory per model)
|
|
161
|
+
errorbars compare out/sshleifer__tiny-gpt2 out/hf-internal-testing__tiny-random-gpt2
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
│ n (shared questions) │ 20 │
|
|
166
|
+
│ mean(sshleifer/tiny-gpt2) │ 0.6000 │
|
|
167
|
+
│ mean(hf-internal-testing/tiny-random-gpt2) │ 0.8000 │
|
|
168
|
+
│ mean diff (A - B) │ -0.2000 │
|
|
169
|
+
│ paired SE │ 0.1376 │
|
|
170
|
+
│ 95% CI │ [-0.4881, 0.0881] │
|
|
171
|
+
│ p-value │ 0.1625 │
|
|
172
|
+
│ McNemar discordant (A wrong/B right, A right/B wrong) │ 6 / 2 │
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
That is a real run, committed under `tests/fixtures/lm_eval_output/` (two tiny models, 20 COPA
|
|
176
|
+
questions). lm-eval's own table says 0.6 ± 0.11 and 0.8 ± 0.09; the paired test on the same 20
|
|
177
|
+
answers gives p = 0.16, so the 20-point gap is not evidence yet. (Rows trimmed; the command prints
|
|
178
|
+
a few more.)
|
|
152
179
|
|
|
153
|
-
|
|
154
|
-
errorbars
|
|
180
|
+
```bash
|
|
181
|
+
errorbars leaderboard out # every model under the output directory
|
|
182
|
+
errorbars compare logs/run-a.eval logs/run-b.eval # Inspect AI logs
|
|
183
|
+
errorbars compare greedy=logs/a.eval sampled=logs/b.eval # two runs of one model, told apart
|
|
184
|
+
errorbars import lm-eval out -o all.csv # or write the canonical CSV once and keep it
|
|
155
185
|
```
|
|
156
186
|
|
|
187
|
+
- **lm-eval**: a `samples_<task>_<timestamp>.jsonl` file, a model's directory, or the whole
|
|
188
|
+
`--output_path`. The samples file does not name its model; lm-eval writes it beside a
|
|
189
|
+
`results_<timestamp>.json` that does, and that is where the name comes from. A samples file
|
|
190
|
+
moved away from it has to be named: `my-model=path/to/samples_copa_....jsonl`. When a directory
|
|
191
|
+
holds several runs of a task, the latest is used and a note says so. Question ids are
|
|
192
|
+
`<task>-<doc_id>`, so several tasks of one model add up to one benchmark.
|
|
193
|
+
- **Inspect AI**: `.eval` (or `.json`) logs; the model is the one in the log. Epochs (`--epochs N`,
|
|
194
|
+
repeated sampling of the same input) land in the `sample` column automatically.
|
|
195
|
+
- With exactly two models in the input, `compare` needs no `--model-a`/`--model-b`: A is the first
|
|
196
|
+
one given. When the two were not scored on the same questions (a different `--limit`, a run
|
|
197
|
+
that crashed), the comparison uses the shared ones and reports how many were left out.
|
|
198
|
+
|
|
157
199
|
`--metric` (lm-eval) picks which computed metric to use as the score when a task reports more than
|
|
158
200
|
one (e.g. `acc` vs. `acc_norm`); it defaults to the first one. `--filter` (lm-eval) picks one filter
|
|
159
201
|
for a task that scores every question under several: `gsm8k_cot_self_consistency` logs each question
|
|
160
202
|
three times (`score-first`, `maj@8`, `maj@64`), and reading those as three times the questions would
|
|
161
203
|
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.
|
|
204
|
+
tasks with more than one.
|
|
164
205
|
|
|
165
206
|
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/
|
|
207
|
+
0.4.13** (`lm_eval run --model dummy --tasks copa --limit 20 --log_samples ...`, a multi-metric
|
|
208
|
+
`arc_easy` run, a three-filter `gsm8k_cot_self_consistency` run, and the two-model output directory
|
|
209
|
+
above) and **inspect-ai 0.3.268** (small tasks through the built-in `mockllm/model` provider: single
|
|
210
|
+
epoch, two epochs, and a scorer with named values). The exact log files are committed as test
|
|
211
|
+
fixtures (`tests/fixtures/samples_*.jsonl`, `tests/fixtures/lm_eval_output/`,
|
|
212
|
+
`tests/fixtures/inspect_*.eval`) and re-parsed in `tests/test_adapters.py` and
|
|
213
|
+
`tests/test_inputs.py` on every run. The Inspect adapter reads logs with Inspect's own
|
|
172
214
|
`inspect_ai.log.read_eval_log` and `inspect_ai.scorer.value_to_float` rather than hand-parsing its
|
|
173
215
|
binary `.eval` format, and needs the `inspect` extra:
|
|
174
216
|
`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.1
|
|
35
|
+
version = "0.2.1"
|
|
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.1
|
|
16
|
+
__version__ = "0.2.1"
|
|
16
17
|
|
|
17
18
|
__all__ = [
|
|
18
19
|
"__version__",
|
|
20
|
+
"load_inputs",
|
|
19
21
|
"MeanEstimate",
|
|
20
22
|
"ClusterDiagnostics",
|
|
21
23
|
"mean_ci_clt",
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Tables for the terminal: rich's when it is installed, aligned plain text when it isn't.
|
|
2
|
+
|
|
3
|
+
The commands build a :class:`Table` and hand it to an :class:`Output`. What reaches the
|
|
4
|
+
terminal follows three rules, each of which the first version of this broke:
|
|
5
|
+
|
|
6
|
+
- A plain ``pip install errorbars`` prints tables. ``rich`` is an extra, and without it the
|
|
7
|
+
commands used to stop and ask for it; now they print the same rows as aligned text.
|
|
8
|
+
- A name is printed as it is. Model names come from the data (``org__model[q4_k_m]``,
|
|
9
|
+
``model:100:latest``), and rich reads ``[...]`` as style markup and ``:name:`` as an emoji,
|
|
10
|
+
so a name lost its brackets or raised ``MarkupError``. Nothing here is parsed as markup.
|
|
11
|
+
- A name is printed whole. Written to a pipe (a CI log, a file), rich lays tables out 80
|
|
12
|
+
columns wide and cuts each cell to fit, which left two models of one organisation with the
|
|
13
|
+
same visible name. A pipe gets the table at its full width, and a terminal too narrow for
|
|
14
|
+
it gets the long cells folded onto more lines.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from dataclasses import dataclass, field
|
|
20
|
+
from typing import Literal
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
from rich.console import Console
|
|
24
|
+
from rich.table import Table as RichTable
|
|
25
|
+
|
|
26
|
+
HAS_RICH = True
|
|
27
|
+
except ImportError: # pragma: no cover - exercised by the test that hides rich
|
|
28
|
+
HAS_RICH = False
|
|
29
|
+
|
|
30
|
+
__all__ = ["HAS_RICH", "Output", "Table"]
|
|
31
|
+
|
|
32
|
+
Justify = Literal["left", "right"]
|
|
33
|
+
|
|
34
|
+
_UNBOUNDED = 100_000
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass
|
|
38
|
+
class Table:
|
|
39
|
+
"""A titled table of text cells."""
|
|
40
|
+
|
|
41
|
+
title: str
|
|
42
|
+
header_style: str = "bold cyan"
|
|
43
|
+
columns: list[tuple[str, Justify]] = field(default_factory=list)
|
|
44
|
+
rows: list[tuple[str, ...]] = field(default_factory=list)
|
|
45
|
+
|
|
46
|
+
def add_column(self, header: str, justify: Justify = "left") -> None:
|
|
47
|
+
self.columns.append((header, justify))
|
|
48
|
+
|
|
49
|
+
def add_row(self, *cells: str) -> None:
|
|
50
|
+
self.rows.append(tuple(cells))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def plain_table(table: Table) -> str:
|
|
54
|
+
"""The table as aligned text: a title, a header, a rule, a line per row."""
|
|
55
|
+
headers = [header for header, _ in table.columns]
|
|
56
|
+
widths = [
|
|
57
|
+
max(len(header), *(len(row[i]) for row in table.rows)) if table.rows else len(header)
|
|
58
|
+
for i, header in enumerate(headers)
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
def line(cells: tuple[str, ...] | list[str]) -> str:
|
|
62
|
+
padded = [
|
|
63
|
+
cell.rjust(width) if justify == "right" else cell.ljust(width)
|
|
64
|
+
for cell, width, (_, justify) in zip(cells, widths, table.columns, strict=True)
|
|
65
|
+
]
|
|
66
|
+
return " ".join(padded).rstrip()
|
|
67
|
+
|
|
68
|
+
lines = [table.title, line(headers), " ".join("-" * width for width in widths)]
|
|
69
|
+
lines.extend(line(row) for row in table.rows)
|
|
70
|
+
return "\n".join(lines)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class Output:
|
|
74
|
+
"""Where a command's tables and notes go: standard output, through rich if it is there."""
|
|
75
|
+
|
|
76
|
+
def __init__(self, *, use_rich: bool | None = None) -> None:
|
|
77
|
+
self._rich = HAS_RICH if use_rich is None else use_rich and HAS_RICH
|
|
78
|
+
self._first = True
|
|
79
|
+
|
|
80
|
+
def _console(self, width: int | None = None) -> Console:
|
|
81
|
+
# No markup, no emoji codes, no highlighting: every string is data.
|
|
82
|
+
return Console(markup=False, emoji=False, highlight=False, width=width)
|
|
83
|
+
|
|
84
|
+
def table(self, table: Table) -> None:
|
|
85
|
+
if not self._rich:
|
|
86
|
+
if not self._first:
|
|
87
|
+
print()
|
|
88
|
+
self._first = False
|
|
89
|
+
print(plain_table(table))
|
|
90
|
+
return
|
|
91
|
+
rendered = RichTable(title=table.title, header_style=table.header_style)
|
|
92
|
+
for header, justify in table.columns:
|
|
93
|
+
# "fold" wraps a cell that doesn't fit; the default ("ellipsis") cuts it. Numbers
|
|
94
|
+
# stay on one line, so it is the names that give way in a narrow terminal.
|
|
95
|
+
rendered.add_column(header, justify=justify, overflow="fold", no_wrap=justify == "right")
|
|
96
|
+
for row in table.rows:
|
|
97
|
+
rendered.add_row(*row)
|
|
98
|
+
console = self._console()
|
|
99
|
+
if not console.is_terminal:
|
|
100
|
+
# Nobody is there to resize a pipe: give the table the width it asks for. (A
|
|
101
|
+
# console measures a table as no wider than itself, so ask a very wide one.)
|
|
102
|
+
needed = self._console(width=_UNBOUNDED).measure(rendered).maximum
|
|
103
|
+
if needed > console.width:
|
|
104
|
+
console = self._console(width=needed)
|
|
105
|
+
console.print(rendered)
|
|
106
|
+
self._first = False
|
|
107
|
+
|
|
108
|
+
def note(self, text: str, style: str | None = None) -> None:
|
|
109
|
+
if self._rich:
|
|
110
|
+
self._console().print(text, style=style)
|
|
111
|
+
else:
|
|
112
|
+
print(text)
|
|
@@ -42,7 +42,8 @@ def load_inspect_log(path: str | Path, scorer: str | None = None) -> EvalData:
|
|
|
42
42
|
from inspect_ai.scorer import value_to_float
|
|
43
43
|
except ImportError as exc: # pragma: no cover - exercised only without the extra
|
|
44
44
|
raise ImportError(
|
|
45
|
-
"
|
|
45
|
+
"reading an Inspect log needs inspect-ai, which the 'inspect' extra installs: "
|
|
46
|
+
'pip install "errorbars[inspect]"'
|
|
46
47
|
) from exc
|
|
47
48
|
|
|
48
49
|
try:
|
|
@@ -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
|