system-one-eval / score.py
blazeofchi's picture
Publish System One Eval v0.1 text benchmark
54c192e verified
Raw History Blame Contribute Delete
2.32 kB
"""Score named typed answers for Structured State Reasoning Probe."""
import argparse
import json
from pathlib import Path
def load_jsonl(path):
return [json.loads(line) for line in Path(path).read_text().splitlines() if line.strip()]
def normalize(spec, raw):
if spec["type"] == "choice":
return raw.get("choice") if isinstance(raw, dict) else raw
if spec["type"] == "noul":
if isinstance(raw, bool):
return raw
if isinstance(raw, dict) and isinstance(raw.get("noul"), (int, float)):
return raw["noul"] >= 0.5
return None
def main():
parser = argparse.ArgumentParser()
parser.add_argument("predictions", help="JSONL rows: task_id and answers map")
parser.add_argument("--dataset", default=str(Path(__file__).resolve().parent / "test.jsonl"))
args = parser.parse_args()
dataset = load_jsonl(args.dataset)
predictions = load_jsonl(args.predictions)
tasks = {row["task_id"]: row for row in dataset}
pred = {row["task_id"]: row for row in predictions}
if len(tasks) != len(dataset) or len(pred) != len(predictions):
raise SystemExit("Duplicate task_id in data or predictions")
if set(tasks) != set(pred):
raise SystemExit(f"Prediction coverage mismatch: missing={sorted(set(tasks)-set(pred))}, extra={sorted(set(pred)-set(tasks))}")
task_pass = question_correct = question_total = 0
per_task = []
for tid, row in tasks.items():
questions = json.loads(row["questions_json"])
gold = json.loads(row["gold_json"])
answers = pred[tid]["answers"]
if set(answers) != set(questions):
raise SystemExit(f"Question coverage mismatch for {tid}")
checks = {qid: normalize(spec, answers[qid]) == gold[qid] for qid, spec in questions.items()}
passed = all(checks.values())
task_pass += passed
question_correct += sum(checks.values())
question_total += len(checks)
per_task.append({"task_id": tid, "pass": passed, "questions": checks})
print(json.dumps({"tasks_passed": task_pass, "tasks_total": len(tasks),
"questions_correct": question_correct, "questions_total": question_total,
"per_task": per_task}, indent=2))
if __name__ == "__main__":
main()