Spaces:
Sleeping
Sleeping
Islam Mamedov commited on
Commit ·
d6df2f2
1
Parent(s): a29c69c
Fix CI recall gate and add workflow badge
Browse filesFiles changed (2)
- README.md+2-1
- src/eval.py+41-25
19 unmodified lines202122232425673 unmodified lines69970070170219 unmodified lines[](https://github.com/islam-mamedov/codebase-rag)[](https://www.python.org/)[](LICENSE)</div>673 unmodified lines**[Try the live demo](https://huggingface.co/spaces/islam-mamedov/fastapi-codebase-qa)**</div>19 unmodified lines20212223242526673 unmodified lines70070170270319 unmodified lines[](https://github.com/islam-mamedov/codebase-rag)[](https://www.python.org/)[](LICENSE)[](https://github.com/islam-mamedov/codebase-rag/actions/workflows/ci.yml)</div>673 unmodified lines**[Try the live demo](https://huggingface.co/spaces/islam-mamedov/fastapi-codebase-qa)**</div>
95 unmodified lines9697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114295 unmodified lines# -------- retrieval metrics --------recalls, mrrs = [], []retrieved_per_q = []for item in items:hits = retrieve(item["question"], k=args.k, mode=args.mode)retrieved_per_q.append(hits)if not item["answerable"]:continuerank = next((r for r, h in enumerate(hits, 1)if is_gold_hit(h, item["gold"])), None)recalls.append(1.0 if rank else 0.0)mrrs.append(1.0 / rank if rank else 0.0)if not rank:print(f" [miss] {item['question']}")if not recalls:raise RuntimeError("The evaluation set contains no answerable questions.")recall_at_k = sum(recalls) / len(recalls)mrr = sum(mrrs) / len(mrrs)print(f"\n=== Retrieval (mode={args.mode}, k={args.k}) ===")print(f"recall@{args.k}: {recall_at_k:.2f} "f"({int(sum(recalls))}/{len(recalls)})")print(f"MRR: {mrr:.2f}")if args.min_recall is not None:if recall_at_k < args.min_recall:print(f"\n[gate] FAIL: recall@{args.k}={recall_at_k:.4f} "f"is below the required {args.min_recall:.4f}")raise SystemExit(1)print(f"\n[gate] PASS: recall@{args.k}={recall_at_k:.4f} "f"meets the required {args.min_recall:.4f}")if not args.answers:print("\n(retrieval-only run; add --answers for generation metrics)")return# -------- generation + judge metrics --------import os95 unmodified lines9697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715895 unmodified lines# -------- retrieval metrics --------recalls, mrrs = [], []retrieved_per_q = []for item in items:hits = retrieve(item["question"], k=args.k, mode=args.mode)retrieved_per_q.append(hits)if not item["answerable"]:continuerank = next((positionfor position, hit in enumerate(hits, 1)if is_gold_hit(hit, item["gold"])),None,)recalls.append(1.0 if rank else 0.0)mrrs.append(1.0 / rank if rank else 0.0)if not rank:print(f" [miss] {item['question']}")if not recalls:raise RuntimeError("The evaluation set contains no answerable questions.")recall_at_k = sum(recalls) / len(recalls)mrr = sum(mrrs) / len(mrrs)print(f"\n=== Retrieval (mode={args.mode}, k={args.k}) ===")print(f"recall@{args.k}: {recall_at_k:.2f} "f"({int(sum(recalls))}/{len(recalls)})")print(f"MRR: {mrr:.2f}")if args.min_recall is not None:if recall_at_k < args.min_recall:print(f"\n[gate] FAIL: recall@{args.k}={recall_at_k:.4f} "f"is below the required {args.min_recall:.4f}")raise SystemExit(1)print(f"\n[gate] PASS: recall@{args.k}={recall_at_k:.4f} "f"meets the required {args.min_recall:.4f}")if not args.answers:print("\n(retrieval-only run; add --answers ""for generation metrics)")return# -------- generation + judge metrics --------import os
README.md+2-1
src/eval.py+41-25