Datasets:
Tasks:
Text Classification
Formats:
parquet
Languages:
English
Size:
1K - 10K
Tags:
structured-decisions
calibration
probabilistic-classification
system-one
workflow-evaluation
Synthetic
License:
bench: save per-decision probabilities and add them to the eval-results PR
#68
by tardellirs - opened
- bench/score_with_jobs.py +10 -4
- bench/submit_results.py +19 -8
bench/score_with_jobs.py
CHANGED
|
@@ -6,7 +6,8 @@ Brier and ECE over the full distributions.
|
|
| 6 |
|
| 7 |
Usage (inside the job, after setup): python bench/score_with_jobs.py MODEL_ID
|
| 8 |
Optional env: SERVE_FLAGS (extra `vllm serve` flags).
|
| 9 |
-
Results are printed and saved to results.json
|
|
|
|
| 10 |
"""
|
| 11 |
import json
|
| 12 |
import math
|
|
@@ -38,7 +39,7 @@ def score_one(pred, gold):
|
|
| 38 |
am_g = g.index(max(g))
|
| 39 |
kl = sum(gi * math.log(gi / max(pi, 1e-9)) for gi, pi in zip(g, p) if gi > 0)
|
| 40 |
brier = sum((pi - gi) ** 2 for pi, gi in zip(p, g))
|
| 41 |
-
return am_p == am_g, kl, brier, max(p)
|
| 42 |
|
| 43 |
|
| 44 |
def main():
|
|
@@ -60,7 +61,7 @@ def main():
|
|
| 60 |
print(f"[bench] server ready for {model}", flush=True)
|
| 61 |
|
| 62 |
ds = load_dataset("LocalLLaMA/typed-decisions", "all", split="test")
|
| 63 |
-
accs, kls, briers, confs = [], [], [], []
|
| 64 |
for i, raw in enumerate(ds):
|
| 65 |
payload = {
|
| 66 |
"model": model,
|
|
@@ -72,7 +73,9 @@ def main():
|
|
| 72 |
answers = r.json()["answers"]
|
| 73 |
gold = json.loads(raw["gold"])
|
| 74 |
for qid, gq in gold.items():
|
| 75 |
-
ok, kl, brier, conf = score_one(answers.get(qid, {"probabilities": {}}), gq)
|
|
|
|
|
|
|
| 76 |
accs.append(ok)
|
| 77 |
kls.append(kl)
|
| 78 |
briers.append(brier)
|
|
@@ -105,6 +108,9 @@ def main():
|
|
| 105 |
}
|
| 106 |
with open("results.json", "w") as f:
|
| 107 |
json.dump(summary, f, indent=2)
|
|
|
|
|
|
|
|
|
|
| 108 |
print(json.dumps(summary, indent=2), flush=True)
|
| 109 |
print("[bench] open a discussion on the dataset with these numbers and the mode (specialist or general).", flush=True)
|
| 110 |
proc.terminate()
|
|
|
|
| 6 |
|
| 7 |
Usage (inside the job, after setup): python bench/score_with_jobs.py MODEL_ID
|
| 8 |
Optional env: SERVE_FLAGS (extra `vllm serve` flags).
|
| 9 |
+
Results are printed and saved to results.json; the normalized probabilities of every
|
| 10 |
+
decision go to predictions.jsonl, one line per decision keyed on case id and question id.
|
| 11 |
"""
|
| 12 |
import json
|
| 13 |
import math
|
|
|
|
| 39 |
am_g = g.index(max(g))
|
| 40 |
kl = sum(gi * math.log(gi / max(pi, 1e-9)) for gi, pi in zip(g, p) if gi > 0)
|
| 41 |
brier = sum((pi - gi) ** 2 for pi, gi in zip(p, g))
|
| 42 |
+
return am_p == am_g, kl, brier, max(p), dict(zip(opts, p))
|
| 43 |
|
| 44 |
|
| 45 |
def main():
|
|
|
|
| 61 |
print(f"[bench] server ready for {model}", flush=True)
|
| 62 |
|
| 63 |
ds = load_dataset("LocalLLaMA/typed-decisions", "all", split="test")
|
| 64 |
+
accs, kls, briers, confs, preds = [], [], [], [], []
|
| 65 |
for i, raw in enumerate(ds):
|
| 66 |
payload = {
|
| 67 |
"model": model,
|
|
|
|
| 73 |
answers = r.json()["answers"]
|
| 74 |
gold = json.loads(raw["gold"])
|
| 75 |
for qid, gq in gold.items():
|
| 76 |
+
ok, kl, brier, conf, probs = score_one(answers.get(qid, {"probabilities": {}}), gq)
|
| 77 |
+
preds.append({"id": raw["id"], "workflow": raw["workflow"], "question": qid,
|
| 78 |
+
"type": gq["type"], "probabilities": probs})
|
| 79 |
accs.append(ok)
|
| 80 |
kls.append(kl)
|
| 81 |
briers.append(brier)
|
|
|
|
| 108 |
}
|
| 109 |
with open("results.json", "w") as f:
|
| 110 |
json.dump(summary, f, indent=2)
|
| 111 |
+
with open("predictions.jsonl", "w") as f:
|
| 112 |
+
for p in preds:
|
| 113 |
+
f.write(json.dumps(p) + "\n")
|
| 114 |
print(json.dumps(summary, indent=2), flush=True)
|
| 115 |
print("[bench] open a discussion on the dataset with these numbers and the mode (specialist or general).", flush=True)
|
| 116 |
proc.terminate()
|
bench/submit_results.py
CHANGED
|
@@ -1,16 +1,20 @@
|
|
| 1 |
"""Create the Typed Decisions eval YAML and open a PR on the model repo.
|
| 2 |
|
| 3 |
Usage:
|
| 4 |
-
python submit_results.py MODEL_ID [RESULTS_JSON] [--mode general|specialist]
|
|
|
|
| 5 |
|
| 6 |
Reads the summary produced by score_with_jobs.py (accuracy, kl_from_gold,
|
| 7 |
brier, ece), writes the Hub eval-results YAML, and opens a pull request on
|
| 8 |
-
the model repo (`.eval_results/<model>.yaml`).
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
"""
|
| 11 |
import argparse
|
| 12 |
import datetime
|
| 13 |
import json
|
|
|
|
| 14 |
|
| 15 |
BENCH = "LocalLLaMA/typed-decisions"
|
| 16 |
TASKS = ["accuracy", "kl_from_gold", "brier", "ece"]
|
|
@@ -45,6 +49,9 @@ def main():
|
|
| 45 |
ap.add_argument("results", nargs="?", default="results.json", help="summary JSON from score_with_jobs.py")
|
| 46 |
ap.add_argument("--mode", choices=["general", "specialist"], default="general",
|
| 47 |
help="specialist = fitted on the benchmark's train split")
|
|
|
|
|
|
|
|
|
|
| 48 |
ap.add_argument("--dry-run", action="store_true", help="print the YAML instead of opening a PR")
|
| 49 |
args = ap.parse_args()
|
| 50 |
|
|
@@ -61,14 +68,18 @@ def main():
|
|
| 61 |
print(yaml_text)
|
| 62 |
return
|
| 63 |
|
| 64 |
-
from huggingface_hub import HfApi
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
api = HfApi()
|
| 67 |
-
commit = api.
|
| 68 |
-
path_or_fileobj=yaml_text.encode(),
|
| 69 |
-
path_in_repo=f".eval_results/{file_name}",
|
| 70 |
repo_id=args.model_id,
|
| 71 |
repo_type="model",
|
|
|
|
| 72 |
create_pr=True,
|
| 73 |
commit_message="Add Typed Decisions eval results",
|
| 74 |
commit_description=(
|
|
@@ -78,7 +89,7 @@ def main():
|
|
| 78 |
),
|
| 79 |
)
|
| 80 |
pr_url = getattr(commit, "pr_url", None) or getattr(commit, "pull_request_url", "")
|
| 81 |
-
print(f"[submit] eval
|
| 82 |
|
| 83 |
|
| 84 |
if __name__ == "__main__":
|
|
|
|
| 1 |
"""Create the Typed Decisions eval YAML and open a PR on the model repo.
|
| 2 |
|
| 3 |
Usage:
|
| 4 |
+
python submit_results.py MODEL_ID [RESULTS_JSON] [--mode general|specialist]
|
| 5 |
+
[--predictions PATH] [--dry-run]
|
| 6 |
|
| 7 |
Reads the summary produced by score_with_jobs.py (accuracy, kl_from_gold,
|
| 8 |
brier, ece), writes the Hub eval-results YAML, and opens a pull request on
|
| 9 |
+
the model repo (`.eval_results/<model>.yaml`). When predictions.jsonl from the
|
| 10 |
+
same run is present (next to RESULTS_JSON unless --predictions says otherwise), the
|
| 11 |
+
PR also adds it as `eval/typed-decisions/predictions.jsonl` so the scores can be
|
| 12 |
+
re-derived. With --dry-run the YAML is printed instead of uploaded.
|
| 13 |
"""
|
| 14 |
import argparse
|
| 15 |
import datetime
|
| 16 |
import json
|
| 17 |
+
import os
|
| 18 |
|
| 19 |
BENCH = "LocalLLaMA/typed-decisions"
|
| 20 |
TASKS = ["accuracy", "kl_from_gold", "brier", "ece"]
|
|
|
|
| 49 |
ap.add_argument("results", nargs="?", default="results.json", help="summary JSON from score_with_jobs.py")
|
| 50 |
ap.add_argument("--mode", choices=["general", "specialist"], default="general",
|
| 51 |
help="specialist = fitted on the benchmark's train split")
|
| 52 |
+
ap.add_argument("--predictions", default=None,
|
| 53 |
+
help="per-decision probabilities from score_with_jobs.py (default: predictions.jsonl next to "
|
| 54 |
+
"the results file), added to the PR if present")
|
| 55 |
ap.add_argument("--dry-run", action="store_true", help="print the YAML instead of opening a PR")
|
| 56 |
args = ap.parse_args()
|
| 57 |
|
|
|
|
| 68 |
print(yaml_text)
|
| 69 |
return
|
| 70 |
|
| 71 |
+
from huggingface_hub import CommitOperationAdd, HfApi
|
| 72 |
|
| 73 |
+
ops = [CommitOperationAdd(path_in_repo=f".eval_results/{file_name}", path_or_fileobj=yaml_text.encode())]
|
| 74 |
+
predictions = args.predictions or os.path.join(os.path.dirname(args.results), "predictions.jsonl")
|
| 75 |
+
if os.path.exists(predictions):
|
| 76 |
+
ops.append(CommitOperationAdd(path_in_repo="eval/typed-decisions/predictions.jsonl",
|
| 77 |
+
path_or_fileobj=predictions))
|
| 78 |
api = HfApi()
|
| 79 |
+
commit = api.create_commit(
|
|
|
|
|
|
|
| 80 |
repo_id=args.model_id,
|
| 81 |
repo_type="model",
|
| 82 |
+
operations=ops,
|
| 83 |
create_pr=True,
|
| 84 |
commit_message="Add Typed Decisions eval results",
|
| 85 |
commit_description=(
|
|
|
|
| 89 |
),
|
| 90 |
)
|
| 91 |
pr_url = getattr(commit, "pr_url", None) or getattr(commit, "pull_request_url", "")
|
| 92 |
+
print(f"[submit] eval results opened as a PR on {args.model_id}: {pr_url}", flush=True)
|
| 93 |
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|