| |
| """Show a few concrete papers — v15 actual n_pred, v16 actual n_pred, n_gt, |
| and what each setting would charge. |
| |
| Stratified pick: small-GT, mid-GT, large-GT to show edge behavior. |
| """ |
| import json |
| import re |
| from pathlib import Path |
|
|
| ROOT = Path("/gpfs/radev/scratch/cohan/yz979/xucai/Abforge_Training") |
|
|
| _TARGET_BULLET_RE = re.compile( |
| r'\n\s*[-*]\s*(?:\*\*)?Target Module(?:\*\*)?\s*:', re.IGNORECASE) |
| _RQ_BULLET_RE = re.compile( |
| r'\n\s*[-*]\s*(?:\*\*)?Research Question(?:\*\*)?\s*:', re.IGNORECASE) |
|
|
|
|
| def extract_result(raw): |
| m = re.search(r"<Result>(.*?)</Result>", raw, re.DOTALL | re.IGNORECASE) |
| if m: return m.group(1) |
| m2 = re.search(r"<Result>(.*)", raw, re.DOTALL | re.IGNORECASE) |
| return m2.group(1) if m2 else raw |
|
|
|
|
| def count_pairs(raw): |
| t = "\n" + extract_result(raw or "") |
| return min(len(_TARGET_BULLET_RE.findall(t)), len(_RQ_BULLET_RE.findall(t))) |
|
|
|
|
| def cp_progressive(n, g, tol, base, step, cap=0.5): |
| excess = max(0, n - g - tol) |
| if excess <= 0: return 0.0 |
| return min(cap, sum(base + step * (i - 1) for i in range(1, excess + 1))) |
|
|
|
|
| def cp_fixed(n, g, tol, rate, cap=0.5): |
| return min(cap, max(0, n - g - tol) * rate) |
|
|
|
|
| SETTINGS = [ |
| ("v16-now", lambda n, g: cp_progressive(n, g, 1, 0.05, 0.01)), |
| ("E (rec)", lambda n, g: cp_progressive(n, g, 2, 0.01, 0.01)), |
| ("A ", lambda n, g: cp_progressive(n, g, 1, 0.01, 0.01)), |
| ("C fixed", lambda n, g: cp_fixed(n, g, 1, 0.02)), |
| ] |
|
|
|
|
| def title_key(r): |
| return r.get("meta", {}).get("title", "") |
|
|
|
|
| v15 = {title_key(json.loads(l)): json.loads(l) |
| for l in open(ROOT / "infer/task1_v15_ckpt100_bench50_qwen3_infer_task1.jsonl")} |
| v16 = {title_key(json.loads(l)): json.loads(l) |
| for l in open(ROOT / "infer/task1_v16_ckpt50_bench50_qwen3_infer_task1.jsonl")} |
| evals = [json.loads(l) for l in open(ROOT / "infer/task1_v15_ckpt100_eval_50.jsonl")] |
|
|
| papers = [] |
| for ev in evals: |
| title = title_key(ev) |
| if title not in v15 or title not in v16: continue |
| n_gt = ev.get("n_gt", 0) |
| n15 = count_pairs(v15[title].get("infer_task1_response", "")) |
| n16 = count_pairs(v16[title].get("infer_task1_response", "")) |
| mr = ev.get("match_rate", 0) |
| papers.append((title, n_gt, n15, n16, mr)) |
|
|
| |
| papers.sort(key=lambda x: x[1]) |
| small = papers[:2] + papers[3:5] |
| mid = [p for p in papers if 3 <= p[1] <= 4][:3] |
| large = [p for p in papers if p[1] >= 6][:3] |
|
|
| print("CASE-BY-CASE count_penalty under each setting") |
| print("=" * 100) |
| print(f"{'title':<55} {'n_gt':>4} {'n15':>4} {'n16':>4} " |
| f"{'v16-now (v15→v16)':>22} {'E (v15→v16)':>16} {'A (v15→v16)':>16} {'C (v15→v16)':>16}") |
| print("-" * 160) |
|
|
| for label, group in [("SMALL n_gt", small), ("MID n_gt", mid), ("LARGE n_gt", large)]: |
| print(f"\n--- {label} ---") |
| for title, n_gt, n15, n16, mr in group: |
| title_s = (title[:50] + "…") if len(title) > 50 else title |
| row = f"{title_s:<55} {n_gt:>4} {n15:>4} {n16:>4} " |
| for name, fn in SETTINGS: |
| p15 = fn(n15, n_gt) |
| p16 = fn(n16, n_gt) |
| row += f" {p15:.3f}→{p16:.3f} " |
| print(row) |
|
|
| |
| print("\n\n=== summary: avg penalty across all 49 papers if model writes constant N ===") |
| print(f"{'setting':<10} {'n=4 (v16 cur)':>15} {'n=5':>10} {'n=6':>10} {'n=7':>10}") |
| for name, fn in SETTINGS: |
| row = f"{name:<10} " |
| for N in [4, 5, 6, 7]: |
| mean = sum(fn(N, p[1]) for p in papers) / len(papers) |
| row += f" {mean:>10.4f} " |
| print(row) |
|
|