jevbench / build_jevbench.py
sileod's picture
Add the build script; card says how to rebuild
5f154ce verified
Raw History Blame Contribute Delete
2.65 kB
"""Recast Praveenrajus/jev-bench into one flat dataset: N rows per data config (model-prediction dumps excluded),
merged, the config as a `task` column, every field a string (soft_label "" when absent). The per-config files
disagree on soft_label's type, so the raw configs cannot be loaded as one dataset.
python build_jevbench.py --out DIR [--push tasksource/jevbench] (or python -m task_diagnostics.build_jevbench)
"""
import argparse, json, random
from pathlib import Path
SRC, REV = "Praveenrajus/jev-bench", "c37b0f6ab1687376ec9ae8dbd9f343163a68252b"
CONFIGS = ("arc_challenge banking77 boolq chaosnli civil_comments clinc150 fever_evidence go_emotions "
"helpsteer2_helpfulness helpsteer2_verbosity ledgar massive measuring_hate_speech mmlu mnli paws "
"sms_spam sst5 strategyqa_closed strategyqa_grounded stsb yelp5").split()
def build(n, seed, splits):
from huggingface_hub import hf_hub_download
out = {}
for split in splits:
rows = []
for c in CONFIGS:
try:
p = hf_hub_download(SRC, f"data/{c}/{split}.jsonl", repo_type="dataset", revision=REV)
except Exception:
continue # chaosnli has a test split only
src = sorted((json.loads(l) for l in open(p)), key=lambda r: r["id"])
random.Random(f"{seed}/{c}/{split}").shuffle(src)
rows += [{"task": c, **{k: "" if r.get(k) is None else str(r[k]) for k in
("id", "primitive", "state", "question", "label", "soft_label", "meta")}} for r in src[:n]]
out[split] = rows
print(f"[jevbench] {split}: {len(rows)} rows over {len({r['task'] for r in rows})} tasks", flush=True)
return out
def main():
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("--out", required=True)
ap.add_argument("--n", type=int, default=200, help="rows per config and split")
ap.add_argument("--splits", default="test,validation")
ap.add_argument("--seed", type=int, default=0)
ap.add_argument("--push", help="hub repo id to push to")
a = ap.parse_args()
data = build(a.n, a.seed, a.splits.split(","))
Path(a.out).mkdir(parents=True, exist_ok=True)
for split, rows in data.items():
(Path(a.out) / f"{split}.jsonl").write_text("".join(json.dumps(r) + "\n" for r in rows))
if a.push:
import datasets
dd = datasets.DatasetDict({s: datasets.Dataset.from_list(r) for s, r in data.items()})
dd.push_to_hub(a.push, commit_message=f"{a.n}/config sample of {SRC}@{REV[:7]}, seed {a.seed}")
if __name__ == "__main__":
main()