File size: 4,641 Bytes
9368cc4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | #!/usr/bin/env python3
"""Choose which tasks ship, so the corpus hits a target resolved rate.
Difficulty is set by composition, not by any one task. Given a measured resolved
rate per tier, this picks how many of each tier to include so the aggregate
lands in the target band, while keeping the easy tier non-empty -- a corpus that
scores a model at zero discriminates no better than one that scores it at 100%.
Rates come from measurement (see CALIBRATION.md); they are inputs here, never
assumptions baked into the selection.
"""
import argparse, collections, json, sys
from pathlib import Path
HERE = Path(__file__).parent
HAND_COMPOUND = {
"incident-triage", "scheduler-regressions", "retry-subsystem-broken",
"api-review-findings", "routing-regressions", "negotiation-and-headers",
"audit-findings",
}
def tier_of(task_id: str) -> str:
if any(k in task_id for k in ("triage3", "review3", "audit3")):
return "d3"
if any(k in task_id for k in ("triage2", "review2", "audit2")):
return "d2"
if task_id.split("-", 1)[1] in HAND_COMPOUND:
return "d3"
return "single"
def load(path: Path):
return [json.loads(line) for line in path.read_text().splitlines() if line.strip()]
def choose(rows, rates, target, total, floor_single, easy_repo="ledger"):
"""Pick counts per tier whose weighted rate is closest to `target`."""
pools = collections.defaultdict(list)
for row in rows:
tier = tier_of(row["task_id"])
# A compound inherits the difficulty of the repo it sits in. The small
# repo can be read end to end, which removes the orientation cost that
# makes compounds hard, so its tasks count as easy however many defects
# they carry.
if tier != "single" and row.get("repo") == easy_repo:
tier = "single"
pools[tier].append(row)
for tasks in pools.values():
tasks.sort(key=lambda r: r["task_id"])
best = None
for n_single in range(floor_single, min(len(pools["single"]), total) + 1):
for n_d2 in range(0, min(len(pools["d2"]), total - n_single) + 1):
n_d3 = total - n_single - n_d2
if n_d3 < 0 or n_d3 > len(pools["d3"]):
continue
solved = (n_single * rates["single"] + n_d2 * rates["d2"]
+ n_d3 * rates["d3"])
rate = solved / total
score = abs(rate - target)
if best is None or score < best[0]:
best = (score, rate, n_single, n_d2, n_d3)
return best, pools
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--corpus", default=str(HERE / "agentic-corpus.jsonl"))
ap.add_argument("--out", default=str(HERE / "agentic-corpus-selected.jsonl"))
ap.add_argument("--total", type=int, default=60)
ap.add_argument("--target", type=float, default=0.175,
help="midpoint of the wanted resolved band")
ap.add_argument("--floor-single", type=int, default=4,
help="minimum easy-tier tasks, so the floor is not zero")
ap.add_argument("--rate-single", type=float, required=True)
ap.add_argument("--rate-d2", type=float, required=True)
ap.add_argument("--rate-d3", type=float, required=True)
ap.add_argument("--easy-repo", default="ledger",
help="repo whose tasks are treated as the easy tier at every "
"defect count, and excluded from the hard tiers")
args = ap.parse_args()
rows = load(Path(args.corpus))
rates = {"single": args.rate_single, "d2": args.rate_d2, "d3": args.rate_d3}
best, pools = choose(rows, rates, args.target, args.total,
args.floor_single, args.easy_repo)
if best is None:
print("no selection satisfies the constraints")
return 1
_, rate, n_single, n_d2, n_d3 = best
picked = (pools["single"][:n_single] + pools["d2"][:n_d2] + pools["d3"][:n_d3])
print(f"measured rates: single={rates['single']:.0%} "
f"d2={rates['d2']:.0%} d3={rates['d3']:.0%}")
print(f"selection ({args.total} tasks): "
f"{n_single} single + {n_d2} two-defect + {n_d3} three-defect")
print(f"projected resolved rate: {rate:.1%}")
langs = collections.Counter(r["lang"] for r in picked)
repos = collections.Counter(r["repo"] for r in picked)
print(f"languages: {dict(langs)}")
print(f"repos: {dict(repos)}")
Path(args.out).write_text("".join(json.dumps(r) + "\n" for r in picked))
print(f"\nwrote {len(picked)} tasks -> {args.out}")
return 0
if __name__ == "__main__":
sys.exit(main())
|