Judge all samples in an eval directory. Returns {doc_id: correct}.
(eval_dir: str, client: AsyncOpenAI, sem: asyncio.Semaphore)
| 159 | |
| 160 | |
| 161 | async def judge_dir(eval_dir: str, client: AsyncOpenAI, sem: asyncio.Semaphore) -> dict[int, bool]: |
| 162 | """Judge all samples in an eval directory. Returns {doc_id: correct}.""" |
| 163 | samples_path = find_samples(eval_dir) |
| 164 | if not samples_path: |
| 165 | print(f"No samples JSONL found in {eval_dir}", file=sys.stderr) |
| 166 | return {} |
| 167 | |
| 168 | samples = load_samples(samples_path) |
| 169 | print(f"Judging {len(samples)} samples from {samples_path}") |
| 170 | |
| 171 | results_path = samples_path.parent / samples_path.name.replace("samples_", "judge_") |
| 172 | existing = load_existing_results(results_path) |
| 173 | if existing: |
| 174 | print( |
| 175 | f" Resuming: {len(existing)} already judged, {len(samples) - len(existing)} remaining" |
| 176 | ) |
| 177 | |
| 178 | pending = [] |
| 179 | for sample in samples: |
| 180 | doc_id = sample["doc_id"] |
| 181 | if doc_id in existing: |
| 182 | continue |
| 183 | ref = extract_reference(sample["doc"]["answer"]) |
| 184 | pending.append(judge_one(sample, ref, client, sem)) |
| 185 | |
| 186 | n_existing = len(existing) |
| 187 | done = 0 |
| 188 | total = n_existing + len(pending) |
| 189 | |
| 190 | with open(results_path, "a") as f: |
| 191 | for coro in asyncio.as_completed(pending): |
| 192 | r = await coro |
| 193 | f.write(json.dumps(r) + "\n") |
| 194 | f.flush() |
| 195 | existing[r["doc_id"]] = r |
| 196 | done += 1 |
| 197 | if done % 100 == 0: |
| 198 | print(f" {n_existing + done}/{total} judged...") |
| 199 | |
| 200 | return {doc_id: r["correct"] for doc_id, r in existing.items()} |
| 201 | |
| 202 | |
| 203 | async def judge_one( |
no test coverage detected