Download scripts/collate_benchmark.py from vineet-datasets/probe-benchmark-600: direct link, hf CLI and curl.
- Browser
- Download file 7.82 kB
-
https://huggingface.co/datasets/vineet-datasets/probe-benchmark-600/resolve/main/scripts/collate_benchmark.py
- Command line
-
hf download hf://datasets/vineet-datasets/probe-benchmark-600/scripts/collate_benchmark.py
-
curl -L -o collate_benchmark.py https://huggingface.co/datasets/vineet-datasets/probe-benchmark-600/resolve/main/scripts/collate_benchmark.py
7.82 kB
| #!/usr/bin/env python3 | |
| """Collate ACCEPTED (verified) questions across the three review banks and | |
| report distributions to plan a balanced 600-question benchmark. | |
| Banks: | |
| qbank rollouts/rollout_vlm_20260827_231647 (count/find/beneath/compare) | |
| count_v2 rollouts/rollout_vlm_20260901_220948 (count, GT=0 hidden via :+nogt0) | |
| find_v2 rollouts/rollout_vlm_20260902_044842 (find, yes-only + 30 broken excl) | |
| Authoritative decision = latest-timestamp record per episode (union across | |
| reviewers), matching review_server.global_decisions(). edited_gt overrides | |
| the stored gt_answer. | |
| """ | |
| import json, glob, os | |
| from collections import Counter, defaultdict | |
| BANKS = { | |
| "qbank": "rollouts/rollout_vlm_20260827_231647", | |
| "count_v2": "rollouts/rollout_vlm_20260901_220948", | |
| "find_v2": "rollouts/rollout_vlm_20260902_044842", | |
| } | |
| # serve-time filters (must mirror start_review_server.sh so we only count | |
| # questions actually in the review pool) | |
| FILTERS = { | |
| "count_v2": {"exclude_gt0": True}, | |
| "find_v2": {"yes_only": True, "use_exclude_file": True}, | |
| "qbank": {}, | |
| } | |
| QCANON = {"counting":"count","existence":"find","under_object":"beneath", | |
| "marked_comparison":"compare"} | |
| def canon(qt): return QCANON.get(qt, qt) | |
| def load_exclude(rd): | |
| p=os.path.join(rd,"EXCLUDE_EPISODES.txt"); out=set() | |
| if os.path.isfile(p): | |
| for line in open(p): | |
| line=line.split("#",1)[0].strip() | |
| if line: out.add(line) | |
| return out | |
| def is_yes(q): | |
| t=str(q.get("gt_answer_text") or "").lower() | |
| if not t: | |
| gt=str(q.get("gt_answer") or ""); om=q.get("option_map") or {} | |
| t=str(om.get(gt) or om.get(gt.upper()) or om.get(gt.lower()) or "").lower() | |
| return t.startswith("y") | |
| def latest_decisions(rd): | |
| """episode -> full latest decision record (by timestamp).""" | |
| out={} | |
| for f in glob.glob(os.path.join(rd,"reviews","*.jsonl")): | |
| if os.path.basename(f)=="claims.jsonl": continue | |
| for line in open(f): | |
| line=line.strip() | |
| if not line: continue | |
| try: d=json.loads(line) | |
| except: continue | |
| ep=d.get("episode") | |
| if not ep: continue | |
| ts=d.get("timestamp","") | |
| if ep not in out or ts>=out[ep].get("timestamp",""): | |
| out[ep]=d | |
| return out | |
| def episode_review(rd, ep): | |
| """Load an episode's review.json (search top-level + worker_*).""" | |
| for cand in [os.path.join(rd,ep,"review.json")] + \ | |
| glob.glob(os.path.join(rd,"worker_*",ep,"review.json")): | |
| if os.path.isfile(cand): | |
| return json.load(open(cand)) | |
| return None | |
| def obj_folders(review): | |
| """Unique asset folders used in the scene (from scene_objects/objects).""" | |
| fs=set() | |
| for o in (review.get("scene_objects") or review.get("objects") or []): | |
| # scene_objects carry ref image paths -> derive folder; | |
| # objects carry name only; fall back to name | |
| imgs=o.get("images") or [] | |
| if imgs: | |
| # "_ref_views/<source__folder>/0.jpg" | |
| part=imgs[0].split("/") | |
| if len(part)>=2: fs.add(part[1]) | |
| elif o.get("folder"): fs.add(o["folder"]) | |
| elif o.get("name"): fs.add("name::"+o["name"]) | |
| return fs | |
| # ---- collate ------------------------------------------------------------- | |
| accepted = defaultdict(list) # canon_type -> [ (bank, ep, review, decision) ] | |
| compare_inverse = Counter() # inverse_status among accepted compare | |
| per_bank_counts = defaultdict(Counter) | |
| for bank, rd in BANKS.items(): | |
| if not os.path.isdir(rd): | |
| print(f"!! missing {rd}"); continue | |
| excl = load_exclude(rd) if FILTERS.get(bank,{}).get("use_exclude_file") else set() | |
| dec = latest_decisions(rd) | |
| for ep, d in dec.items(): | |
| if d.get("status")!="accepted": | |
| continue | |
| if ep in excl: | |
| continue | |
| rv = episode_review(rd, ep) | |
| if rv is None: | |
| continue | |
| q = rv.get("question") or {} | |
| ct = canon(q.get("question_type")) | |
| # apply serve filters | |
| if FILTERS.get(bank,{}).get("exclude_gt0") and str(q.get("gt_answer"))=="0": | |
| continue | |
| if FILTERS.get(bank,{}).get("yes_only") and not is_yes(q): | |
| continue | |
| accepted[ct].append((bank, ep, rv, d)) | |
| per_bank_counts[bank][ct]+=1 | |
| if ct=="compare": | |
| compare_inverse[d.get("inverse_status") or "not_annotated"]+=1 | |
| # ---- report -------------------------------------------------------------- | |
| print("="*70) | |
| print("ACCEPTED (verified) QUESTION COUNTS — final benchmark candidate pool") | |
| print("="*70) | |
| grand=0 | |
| for ct in ["count","find","beneath","compare"]: | |
| n=len(accepted[ct]); grand+=n | |
| srcs=Counter(b for b,_,_,_ in accepted[ct]) | |
| print(f" {ct:9s}: {n:4d} (by bank: {dict(srcs)})") | |
| print(f" {'TOTAL':9s}: {grand:4d}") | |
| print("\n" + "="*70) | |
| print("COMPARE — inverse-question annotation") | |
| print("="*70) | |
| tot_cmp=len(accepted['compare']) | |
| inv_acc=compare_inverse.get('accepted',0) | |
| print(f" accepted compare questions : {tot_cmp}") | |
| print(f" ...with inverse ALSO accepted (good) : {inv_acc}") | |
| print(f" ...inverse rejected : {compare_inverse.get('rejected',0)}") | |
| print(f" ...inverse not annotated : {compare_inverse.get('not_annotated',0)}") | |
| print(f" → usable as TWO questions (fwd+inverse): {inv_acc} pairs " | |
| f"(= {tot_cmp}+{inv_acc} = {tot_cmp+inv_acc} total if both counted)") | |
| # ---- GT distribution per type ------------------------------------------- | |
| def gt_of(rv, d): | |
| q=rv.get("question") or {} | |
| if d.get("edited_gt") is not None: return str(d["edited_gt"]) | |
| return str(q.get("gt_answer")) | |
| print("\n" + "="*70) | |
| print("GROUND-TRUTH DISTRIBUTION (accepted only; edited_gt applied)") | |
| print("="*70) | |
| # count / beneath -> integer or option | |
| for ct in ["count"]: | |
| c=Counter(gt_of(rv,d) for _,_,rv,d in accepted[ct]) | |
| print(f" {ct}: {dict(sorted(c.items(), key=lambda x:str(x[0])))}") | |
| # find -> yes/no (yes-only expected) | |
| c=Counter("yes" if is_yes(rv.get("question") or {}) else "no" | |
| for _,_,rv,d in accepted["find"]) | |
| print(f" find (yes/no): {dict(c)}") | |
| # beneath -> gt is object name; report count of distinct answers + option letter | |
| bl=Counter(gt_of(rv,d) for _,_,rv,d in accepted["beneath"]) | |
| print(f" beneath: {len(bl)} distinct GT answers among {sum(bl.values())} (top5: {bl.most_common(5)})") | |
| # compare -> A/B/C letter + polarity | |
| cl=Counter(gt_of(rv,d) for _,_,rv,d in accepted["compare"]) | |
| pol=Counter((rv.get('question') or {}).get('comparison_extremum') | |
| for _,_,rv,d in accepted["compare"]) | |
| print(f" compare letter: {dict(sorted(cl.items()))}") | |
| print(f" compare extremum (largest/smallest): {dict(pol)}") | |
| # ---- unique-object usage ------------------------------------------------- | |
| print("\n" + "="*70) | |
| print("UNIQUE OBJECTS USED (across accepted scenes, per type)") | |
| print("="*70) | |
| all_objs=set() | |
| for ct in ["count","find","beneath","compare"]: | |
| objs=set() | |
| for _,_,rv,_ in accepted[ct]: | |
| objs|=obj_folders(rv) | |
| all_objs|=objs | |
| print(f" {ct:9s}: {len(objs)} unique object folders across {len(accepted[ct])} scenes") | |
| print(f" {'UNION':9s}: {len(all_objs)} unique object folders across the whole pool") | |
| # ---- target-object diversity (the queried/counted object) --------------- | |
| print("\n" + "="*70) | |
| print("TARGET / QUERIED OBJECT DIVERSITY (the object the question is ABOUT)") | |
| print("="*70) | |
| for ct in ["count","find","beneath"]: | |
| tgt=Counter() | |
| for _,_,rv,_ in accepted[ct]: | |
| q=rv.get("question") or {} | |
| name=q.get("target_name") or q.get("queried_name") | |
| if name: tgt[name]+=1 | |
| print(f" {ct:9s}: {len(tgt)} distinct target objects; " | |
| f"most reused: {tgt.most_common(3)}") | |
| print("\n(done)") | |