Download scripts/plan_options.py from vineet-datasets/probe-benchmark-600: direct link, hf CLI and curl.
- Browser
- Download file 5.45 kB
-
https://huggingface.co/datasets/vineet-datasets/probe-benchmark-600/resolve/main/scripts/plan_options.py
- Command line
-
hf download hf://datasets/vineet-datasets/probe-benchmark-600/scripts/plan_options.py
-
curl -L -o plan_options.py https://huggingface.co/datasets/vineet-datasets/probe-benchmark-600/resolve/main/scripts/plan_options.py
5.45 kB
| #!/usr/bin/env python3 | |
| """Compare NO-fill options for count/find using ONLY existing material. | |
| Signature (asked-object): | |
| count -> target_ref_folder ; find -> queried_ref_folder | |
| Options: | |
| B2 : YES cap 2, NO disjoint (asked-obj never a yes-target) | |
| B3 : YES cap 3, NO disjoint | |
| A : per-asked-object cap C over YES+NO COMBINED (NO may reuse a yes-target, | |
| but total questions asking about any one object <= C). No disjoint rule. | |
| Reports total reachable /150 and resulting diversity. | |
| """ | |
| import json, glob, os, sys | |
| from collections import Counter, defaultdict | |
| BANK="approved-questions/bank" | |
| SRC={"count_v2":"rollouts/rollout_vlm_20260901_220948", | |
| "find_v2":"rollouts/rollout_vlm_20260902_044842", | |
| "qbank":"rollouts/rollout_vlm_20260827_231647"} | |
| N=150 | |
| def qtype(q): | |
| t=q.get("question_type") | |
| return {"marked_comparison":"compare","counting":"count", | |
| "existence":"find","under_object":"beneath"}.get(t,t) | |
| def scene_folders(ep_dir): | |
| sp=os.path.join(ep_dir,"scene_snapshot","scene_snapshot.json"); s=set() | |
| if os.path.isfile(sp): | |
| j=json.load(open(sp)) | |
| for o in (j.get("objects") or []): | |
| if o.get("folder"): s.add(o["folder"]) | |
| return s | |
| def approved_yes(ct): | |
| rows=[] | |
| for rj in sorted(glob.glob(f"{BANK}/ep_*/review.json")): | |
| d=json.load(open(rj)); q=d.get("question") or {} | |
| if qtype(q)!=ct: continue | |
| if ct=="count": | |
| if str(q.get("gt_answer"))=="0": continue | |
| fol=q.get("target_ref_folder") | |
| else: | |
| if not str(q.get("gt_answer_text") or "").lower().startswith("y"): continue | |
| fol=q.get("queried_ref_folder") | |
| ep_dir=os.path.dirname(rj) | |
| rows.append({"name":os.path.basename(ep_dir),"src":"approved","polarity":"yes", | |
| "fol":fol,"scene":scene_folders(ep_dir)}) | |
| return rows | |
| def available_no(ct): | |
| rows=[]; seen=set() | |
| for bank,rd in SRC.items(): | |
| if not os.path.isdir(rd): continue | |
| for rj in glob.glob(os.path.join(rd,"ep_*/review.json"))+\ | |
| glob.glob(os.path.join(rd,"worker_*/ep_*/review.json")): | |
| ep_dir=os.path.dirname(rj); nm=os.path.basename(ep_dir) | |
| key=(bank,nm) | |
| if key in seen: continue | |
| try:d=json.load(open(rj)) | |
| except:continue | |
| q=d.get("question") or {} | |
| if qtype(q)!=ct: continue | |
| if ct=="count": | |
| if str(q.get("gt_answer"))!="0": continue | |
| fol=q.get("target_ref_folder") | |
| else: | |
| if not str(q.get("gt_answer_text") or "").lower().startswith("n"): continue | |
| fol=q.get("queried_ref_folder") | |
| seen.add(key) | |
| rows.append({"name":nm,"src":bank,"polarity":"no","fol":fol, | |
| "scene":scene_folders(ep_dir)}) | |
| return rows | |
| def marg(scene,g): return len(scene-g) | |
| def cap_select(rows, need, cap, g, exclude_names=(), forbid=None, used0=None): | |
| """Round-robin over asked-obj, cap each, diversity tiebreak on scene folders. | |
| forbid: set of asked-obj folders that may NOT be used at all.""" | |
| by=defaultdict(list) | |
| for r in rows: | |
| if not r["fol"]: continue | |
| if forbid and r["fol"] in forbid: continue | |
| by[r["fol"]].append(r) | |
| used=Counter(used0 or {}); sel=[]; chosen=set(exclude_names) | |
| for rnd in range(cap): | |
| if len(sel)>=need: break | |
| order=sorted(by, key=lambda k:(-max((marg(e["scene"],g) for e in by[k] | |
| if e["name"] not in chosen),default=-1),str(k))) | |
| progressed=False | |
| for k in order: | |
| if len(sel)>=need: break | |
| if used[k]!=rnd: continue | |
| pool=[e for e in by[k] if e["name"] not in chosen] | |
| if not pool: continue | |
| pool.sort(key=lambda e:(-marg(e["scene"],g),e["name"])) | |
| e=pool[0]; sel.append(e); g|=e["scene"]; used[k]+=1 | |
| chosen.add(e["name"]); progressed=True | |
| if not progressed: break | |
| return sel, used | |
| def run(ct, mode): | |
| yes=approved_yes(ct); no=available_no(ct) | |
| g=set() | |
| if mode in ("B2","B3"): | |
| yes_cap=2 if mode=="B2" else 3 | |
| ysel,_=cap_select(yes, N, yes_cap, g) | |
| yes_objs={c["fol"] for c in ysel} | |
| need=N-len(ysel) | |
| nsel,_=cap_select(no, need, 2, g, forbid=yes_objs) # disjoint | |
| else: # Option A: combined cap C=3 over yes+no, no disjoint | |
| C=3 | |
| ysel,used=cap_select(yes, N, C, g) | |
| yes_objs={c["fol"] for c in ysel} | |
| need=N-len(ysel) | |
| # continue capping across yes+no combined: pass used counts forward | |
| nsel,_=cap_select(no, need, C, g, used0=used) | |
| total=len(ysel)+len(nsel) | |
| no_objs={c["fol"] for c in nsel} | |
| all_objs=yes_objs|no_objs | |
| return dict(ct=ct,mode=mode,yes=len(ysel),no=len(nsel),total=total, | |
| yes_obj=len(yes_objs),no_obj=len(no_objs),all_obj=len(all_objs), | |
| gscene=len(g)) | |
| print(f"{'type':6} {'mode':4} {'yes':>4} {'no':>4} {'total':>6} " | |
| f"{'yes_obj':>8} {'no_obj':>7} {'asked_obj':>10} {'scene_folders':>14}") | |
| for ct in ["count","find"]: | |
| for mode in ["B2","B3","A"]: | |
| r=run(ct,mode) | |
| flag = "" if r["total"]>=N else f" SHORT {N-r['total']}" | |
| print(f"{ct:6} {mode:4} {r['yes']:>4} {r['no']:>4} {r['total']:>6} " | |
| f"{r['yes_obj']:>8} {r['no_obj']:>7} {r['all_obj']:>10} " | |
| f"{r['gscene']:>14}{flag}") | |