mallard-data / score.py
azettl's picture
Mallard training data and test tasks
babfcd9 verified
Raw History Blame Contribute Delete
1.39 kB
"""Score a model's raw outputs on the duckwork-test tasks.
python score.py outputs.jsonl [--sample]
`outputs.jsonl` has one line per task: {"id": ..., "output": "<raw model text>"}.
Render each task with your model's chat template (system prompt, tools,
messages; thinking off), generate greedily, and keep the raw text, tool-call
markup included. `--sample` scores only the 308 tasks in the published
benchmark sample. Needs checks.py next to this file.
"""
import collections
import json
import pathlib
import sys
from checks import check
HERE = pathlib.Path(__file__).parent
def main() -> None:
outputs = {(r := json.loads(l))["id"]: r["output"] for l in open(sys.argv[1]) if l.strip()}
only_sample = "--sample" in sys.argv
passed, total = collections.Counter(), collections.Counter()
for line in open(HERE / "duckwork-test" / "test.jsonl"):
task = json.loads(line)
if (only_sample and not task["in_benchmark_sample"]) or task["id"] not in outputs:
continue
result = check({"expect": json.loads(task["expect"])}, outputs[task["id"]])
total[task["kind"]] += 1
passed[task["kind"]] += result["passed"]
for kind in sorted(total):
print(f"{kind:20} {passed[kind]:4} / {total[kind]}")
print(f"{'total':20} {sum(passed.values()):4} / {sum(total.values())}")
if __name__ == "__main__":
main()