Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .agents/skill-library/evaluation/label-benchmark/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ gated download), propose `units.public_ids` in the same diff: the path where it
```bash
PYTHONPATH=REPO/app python3 -c 'from nullius.standard.contract import definitions as d; print(d.version_identity(d.get("benchmark", "REF")))'
```
- `copies`, beside `labels`, when one dataset holds tasks of another: each map names the `dataset` it maps, the
dataset `of` the same tasks, `checked` as above, and `tasks` as `[unit, its unit there]` pairs, same ids included.
The Leaderboard then counts a mapped task once, as its copy, with its copy's labels (step 1). One map
per dataset and version, never onto a dataset that is itself mapped. Under `units.redistribute: false` with no
`units.public_ids`, none.

```json
{"schema": 1, "labels": [...], "copies": [
{"dataset": "lite", "of": "full", "checked": ["IDENTITY"], "tasks": [["1", "7"], ["2", "2"]]}
]}
```
- A new version: add its identity, as the command above prints it for the new `REF`, to `checked` only for the tasks
whose bytes did not change, and only when the `policy` and whatever else a state is built from or a task is graded
by did not change either. Every other task goes through the steps.
Expand All @@ -120,6 +131,12 @@ through the steps and write its `tasks` rules for both. Either differs (a workfl
Datasets with the same task ids, questions and expected answers, differing only in the context around them (a longer
history), are the same tasks at another size: take the smallest through the steps and write its `tasks` rules for each.
The same tasks in another language: take every language through the steps; a label stands where all agree, for each.
A copy is the same question with the same expected answer, in another dataset or under another id (a lite list of a
full one, an older release kept beside a newer one): map it (`copies`), matched on the task's data, every field but
its id, never on the id alone. A variant (another context size, another language, a corrected answer) is never a
copy: it keeps its own tasks and its own labels.
Where a map is checked at `REF`, it comes before the rules above: label the dataset mapped onto, and write `tasks`
rules for the mapped dataset only for units no map covers or versions no map is checked at.

This step decides only a yes, and only from a field of the task's data that anyone can check again. A field whose
value, when present and not empty, is the axis's test gives a `tasks` rule over those tasks: a graded check that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
PYTHONPATH=REPO/app python3 SKILL/scripts/public_ids.py ENTRY

Such a benchmark's labels may name tasks only under ``units.public_ids``, the path in the upstream repository where
it publishes the ids, and only ids that are, at each version a rule is ``checked`` at:
it publishes the ids, and only ids that are, at each version a rule or a map of ``copies`` is ``checked`` at:
- listed by ``units`` for that dataset (the listing Nullius cached when the skill listed it);
- published: the upstream fetched at its pinned commit over HTTPS, with no credential, no user configuration and an
empty home (a private repository fails here), and the id found under that path as a tracked file or folder name
Expand Down Expand Up @@ -36,21 +36,32 @@ def refusals(document, versions, listed, published) -> list:
unit = versions[0].get("units") or {}
if unit.get("redistribute") is not False:
return []
rules = [r for r in document["labels"] if "tasks" in r]
if rules and not unit.get("public_ids"):
named = _named(document)
if named and not unit.get("public_ids"):
return ["units.public_ids: not set, so no task id may be named"]
out = []
for v in sorted({v for r in rules for v in r["checked"]}):
for ds in sorted({r["dataset"] for r in rules if v in r["checked"]}):
ids = {t for r in rules if v in r["checked"] and r["dataset"] == ds for t in r["tasks"]}
there = listed.get((v, ds))
if there is None:
out.append(f"{v} {ds}: no cached listing; list its units first")
continue
if ids - set(there):
out.append(f"{v} {ds}: {len(ids - set(there))} of {len(ids)} ids not listed")
if ids - published.get(v, set()):
out.append(f"{v} {ds}: {len(ids - published.get(v, set()))} of {len(ids)} ids not published under {unit['public_ids']}")
for (v, ds), ids in sorted(named.items()):
there = listed.get((v, ds))
if there is None:
out.append(f"{v} {ds}: no cached listing; list its units first")
continue
if ids - set(there):
out.append(f"{v} {ds}: {len(ids - set(there))} of {len(ids)} ids not listed")
if ids - published.get(v, set()):
out.append(f"{v} {ds}: {len(ids - published.get(v, set()))} of {len(ids)} ids not published under {unit['public_ids']}")
return out


def _named(document) -> dict:
"""Every task id the document names, by (version, dataset): its ``tasks`` rules' and both sides of its maps."""
out = {}
for r in document["labels"]:
for v in r.get("checked", []) if "tasks" in r else []:
out.setdefault((v, r["dataset"]), set()).update(r["tasks"])
for c in document.get("copies", []):
for v in c["checked"]:
for side, ds in enumerate((c["dataset"], c["of"])):
out.setdefault((v, ds), set()).update(p[side] for p in c["tasks"])
return out


Expand Down Expand Up @@ -107,13 +118,13 @@ def main():
with open(os.path.join(entry, "labels.json"), encoding="utf-8") as f:
document = json.load(f)
by = {definitions.version_identity(b): b for b in versions}
rules = [r for r in document.get("labels") or [] if isinstance(r, dict) and "tasks" in r]
unit = (versions[0].get("units") or {}) if versions else {}
listed, seen = {}, {}
if versions and not labels.check(document, versions).problems and unit.get("redistribute") is False and unit.get("public_ids"):
for v in {v for r in rules for v in r["checked"]}:
named = _named(document)
for v in {v for v, _ in named}:
b = by[v]
for ds in {r["dataset"] for r in rules if v in r["checked"]}:
for ds in {ds for at, ds in named if at == v}:
d = next(x for x in b["datasets"] if x["id"] == ds)
try:
with open(units.cache_path(b, d, units.option_values(b, ds)), encoding="utf-8") as f:
Expand All @@ -123,7 +134,7 @@ def main():
where = (b["upstream"]["repository"], b["upstream"]["tested"], unit["public_ids"])
seen[v] = published(*where)
out = refusals(document, versions, listed, seen)
ids = sum(len(r["tasks"]) for r in rules if isinstance(r.get("tasks"), list))
ids = sum(map(len, _named(document).values())) if not labels.check(document, versions).problems else 0
if not out and unit.get("redistribute") is not False:
print("units.redistribute is not false in ENTRY: its ids may be named; apply a proposed change first")
else:
Expand Down
74 changes: 71 additions & 3 deletions app/nullius/leaderboard/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

A ``tasks`` rule names the versions its ids were ``checked`` at, as a run records them
(``definitions.version_identity``). At another version it counts only when asked (``include``).

``copies`` maps tasks of one dataset onto the same tasks of another, unit by unit, at the versions ``checked``:
a true copy is the same question with the same expected answer, in another list or under another id. A variant (a
longer context, another language) measures something else and is never mapped. A mapped task is its copy's, labels
included; at another version the map is not applied. A map that does not read is left out alone and said.
"""
from __future__ import annotations

Expand All @@ -29,6 +34,7 @@
AXES = CAPABILITIES + DOMAINS
UNCHECKED = ("omit", "include")
_KEYS = {"dataset", "tasks", "checked", "axes", "not"}
_COPY_KEYS = {"dataset", "of", "checked", "tasks"}


@dataclass(frozen=True)
Expand All @@ -40,10 +46,28 @@ class Rule:
checked: frozenset = frozenset()


@dataclass(frozen=True)
class Copies:
dataset: str
of: str # the dataset that holds the same tasks
checked: frozenset
tasks: tuple # (unit, the same task's unit in ``of``) pairs


@dataclass(frozen=True)
class Labels:
rules: tuple = ()
problems: tuple = ()
copies: tuple = ()

def same(self, version: str, dataset: str) -> dict:
"""The tasks of this whole dataset at this version that are copies, each as (dataset, unit) of its copy."""
return {unit: (c.of, to) for c in self.copies if c.dataset == dataset and version in c.checked for unit, to in c.tasks}

def unchecked_copies(self, version: str) -> int:
"""How many tasks a map names that no map checked at this version maps, each (dataset, unit) once."""
mapped = lambda at: {(c.dataset, unit) for c in self.copies if (version in c.checked) == at for unit, _ in c.tasks}
return len(mapped(False) - mapped(True))

def unchecked(self, version: str) -> list:
"""The ``tasks`` rules not checked at this version."""
Expand Down Expand Up @@ -111,11 +135,48 @@ def _rule(rule, shapes, task_ids):
return Rule(frozenset(rule.get("axes", [])), frozenset(rule.get("not", [])), dataset, frozenset(rule["tasks"]), frozenset(rule["checked"]))


def _copy(entry, shapes, task_ids, kept):
"""The map, or why it does not read; ``kept`` the maps read before it."""
if not isinstance(entry, dict):
return "an object"
if set(entry) != _COPY_KEYS:
return f"{', '.join(sorted(_COPY_KEYS))}, and nothing else"
if not task_ids:
return "this benchmark's ids may not be redistributed (units.redistribute, no units.public_ids); no map"
dataset, of = entry["dataset"], entry["of"]
if not (isinstance(dataset, str) and dataset and isinstance(of, str) and of):
return "dataset and of: dataset ids"
if dataset == of:
return "of: a map onto itself"
if not _names(entry["checked"]):
return "checked: the versions these tasks were checked at"
unknown = [v for v in entry["checked"] if v not in shapes]
if unknown:
return f"checked: unknown version {unknown[0]!r}; one of {', '.join(shapes)}"
for v in entry["checked"]:
for d in (dataset, of):
if _whole(d, [shapes[v]]):
return f"{_whole(d, [shapes[v]])}, at {v}"
pairs = entry["tasks"]
if not (isinstance(pairs, list) and pairs and all(isinstance(p, list) and len(p) == 2 and _names(p) for p in pairs)):
return "tasks: [unit, its copy's unit] pairs, never empty"
for side, name in ((0, dataset), (1, of)):
if len({p[side] for p in pairs}) < len(pairs):
return f"tasks: a unit of {name} mapped twice"
for c in kept:
if set(entry["checked"]) & c.checked:
if dataset == c.dataset:
return f"dataset: {dataset} already has a map at a version"
if dataset == c.of or of == c.dataset:
return "of: a chain of maps; map each onto the last"
return Copies(dataset, of, frozenset(entry["checked"]), tuple(map(tuple, pairs)))


def check(document, versions) -> Labels:
"""A ``labels.json`` document against its benchmark, ``versions`` the benchmark resolved at each of its versions."""
if not isinstance(document, dict) or document.get("schema") != SCHEMA or not isinstance(document.get("labels"), list) \
or set(document) != {"schema", "labels"}:
return Labels(problems=(f"{{schema: {SCHEMA}, labels: [...]}} and nothing else",))
or not isinstance(document.get("copies", []), list) or set(document) - {"copies"} != {"schema", "labels"}:
return Labels(problems=(f"{{schema: {SCHEMA}, labels: [...], copies?: [...]}} and nothing else",))
shapes = {} # each version's whole datasets and its cuts
for b in versions:
cuts = {d["id"]: d["subset_of"] for d in b.get("datasets") or [] if d.get("subset_of")}
Expand All @@ -129,7 +190,14 @@ def check(document, versions) -> Labels:
rules.append(got)
else:
problems.append(f"labels[{i}]: {got}")
return Labels(tuple(rules), tuple(problems))
copies = []
for i, entry in enumerate(document.get("copies", [])):
got = _copy(entry, shapes, task_ids, copies)
if isinstance(got, Copies):
copies.append(got)
else:
problems.append(f"copies[{i}]: {got}")
return Labels(tuple(rules), tuple(problems), tuple(copies))


def load(benchmarks) -> dict:
Expand Down
48 changes: 36 additions & 12 deletions app/nullius/leaderboard/projection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Each axis scored over the tasks labelled with it. It reads no file.

A task is ``Job.task_id`` with its dataset replaced by the one its list is cut from (``subset_of``), so a cut's
tasks are the whole dataset's. Two versions of a benchmark are two sets of tasks: nothing pools across them, and a
tasks are the whole dataset's, then by its copy's where the labels map it (``labels.Copies``), so one question in two
lists counts once, its own labels and listing aside. Two versions of a benchmark are two sets of tasks: nothing pools across them, and a
cell they both reach keeps its rates per version only.

Per row, the most recent run of each recorded benchmark version and dataset counts, ties by job id; each other
Expand All @@ -20,7 +21,8 @@
apart as a cell's rates are, a version with no task it reads there left out: beside the cells, per axis under
``evidence``, in no rate. Coverage is a row's evaluated tasks of an axis over the tasks the labels give it at the
versions its own runs record, counted from the listings given; ``labelled`` is None, shown "?", when one of them is
missing, lacks a task any row recorded, or a run records a dataset its version does not declare.
missing, lacks a task any row recorded under that list's own id or a listed copy's task, or a run records a dataset
its version does not declare.
"""
from __future__ import annotations

Expand Down Expand Up @@ -88,7 +90,7 @@ def _value(trial, verified):
return (0, 0) if verified else None


def _tasks(jobs, whole, axes_of) -> tuple[dict, list, list]:
def _tasks(jobs, task_of, axes_of) -> tuple[dict, list, list]:
"""One row's tasks by id, the runs they come from and its warnings."""
winners, warnings = select(jobs)
tasks = {}
Expand All @@ -101,7 +103,7 @@ def _tasks(jobs, whole, axes_of) -> tuple[dict, list, list]:
for t in same:
tid = job.task_id(t)
if tid:
groups.setdefault(tid[:2] + (whole(*tid[:3]), tid[3]), []).append(t)
groups.setdefault(task_of(*tid), []).append(t)
unresolved = sum(job.task_id(t) is None for t in same)
if unresolved:
warnings.append(f"{job.job_id}: {unresolved} trials match no task: the task's identity could not be established")
Expand Down Expand Up @@ -275,14 +277,25 @@ def _base(unchecked, axes, cohort, defined, listings, labels, rows) -> dict:
def whole(benchmark, version, dataset):
return next((cut for d, cut in defined.get((benchmark, version), ()) if d == dataset), None) or dataset

copied, observed = {}, {}

def same(benchmark, version, dataset, unit):
"""The task's id: its whole dataset's, then its copy's. The unit is kept as its own list recorded it, which its
listing is checked against."""
dataset = whole(benchmark, version, dataset)
observed.setdefault((benchmark, version), {}).setdefault(dataset, set()).add(unit)
if (benchmark, version, dataset) not in copied:
copied[benchmark, version, dataset] = labels.get(benchmark, none).same(version, dataset)
return (benchmark, version, *copied[benchmark, version, dataset].get(unit, (dataset, unit)))

cache = {}

def axes_of(tid):
if tid not in cache:
cache[tid] = labels.get(tid[0], none).axes(*tid[1:], unchecked)
return cache[tid]

per_row = {key: _tasks(jobs, whole, axes_of) for key, jobs in rows.items()}
per_row = {key: _tasks(jobs, same, axes_of) for key, jobs in rows.items()}
evaluated = {key: {tid for tid, t in tasks.items() if t.resolved is not None} for key, (tasks, _, _) in per_row.items()}
# nothing asked: the rows a shown axis can score; one with other tasks only would leave no task shared
cohort = (list(dict.fromkeys(cohort)) if cohort is not None else
Expand All @@ -300,15 +313,16 @@ def holders(tids):
n = sum(len(r.tasks) for r in own.unchecked(version))
if n:
warnings.append(f"{benchmark} {version}: {n} task labels not checked at this version")
n = own.unchecked_copies(version)
if n:
warnings.append(f"{benchmark} {version}: {n} task copies not checked at this version, counted apart")

recorded = {}
for tasks, runs, _ in per_row.values():
recorded = observed
for _, runs, _ in per_row.values():
for j in runs: # a run with no task still records its dataset
at = (j.identity["benchmark"], j.identity["benchmark_version"])
if j.dataset:
recorded.setdefault(at, {}).setdefault(whole(*at, j.dataset), set())
for tid in tasks:
recorded.setdefault(tid[:2], {}).setdefault(tid[2], set()).add(tid[3])

def labelled(benchmark, version):
"""How many tasks of one benchmark version the labels give each axis; None where a listing is missing or wrong."""
Expand All @@ -321,13 +335,23 @@ def labelled(benchmark, version):
counts.update(dict.fromkeys(own.may(version, dataset, unchecked)))
for dataset in declared:
units = listings.get((benchmark, version, dataset))
stray = recorded.get((benchmark, version), {}).get(dataset, set()) - set(units or ())
seen_here = recorded.get((benchmark, version), {}).get(dataset, set())
copies = own.same(version, dataset)
lost = {} # a listed or recorded copy its copy's listing lacks
for unit in (set(units or ()) | seen_here) & set(copies):
there = listings.get((benchmark, version, copies[unit][0]))
if there is not None and copies[unit][1] not in there:
lost.setdefault(copies[unit][0], set()).add(unit)
for of, missing in sorted(lost.items()):
warnings.append(f"{benchmark} {version} {dataset}: {len(missing)} copies are not in {of}'s listing")
counts.update(dict.fromkeys(own.may(version, dataset, unchecked) | own.may(version, of, unchecked)))
stray = seen_here - set(units or ())
if units is not None and stray:
warnings.append(f"{benchmark} {version} {dataset}: {len(stray)} recorded tasks are not in its listing")
if units is None or stray:
if units is None or stray or lost:
counts.update(dict.fromkeys(own.may(version, dataset, unchecked)))
continue
for unit in set(units):
for unit in set(units) - set(copies): # a copy counts where its copy is listed
for a in axes_of((benchmark, version, dataset, unit)):
if counts.get(a, 0) is not None:
counts[a] = counts.get(a, 0) + 1
Expand Down
Loading
Loading