Datasets:
Download scripts/aggregate.py from Lux1997/eMCR: direct link, hf CLI and curl.
- Browser
- Download file 3.11 kB
-
https://huggingface.co/datasets/Lux1997/eMCR/resolve/main/scripts/aggregate.py
- Command line
-
hf download hf://datasets/Lux1997/eMCR/scripts/aggregate.py
-
curl -L -o aggregate.py https://huggingface.co/datasets/Lux1997/eMCR/resolve/main/scripts/aggregate.py
3.11 kB
| """Aggregate runs/full/<model>/<benchmark>/*.json into comparison tables. | |
| - Per-benchmark macro-averaged metrics across that benchmark's tasks, per model. | |
| - For multi-condition stratified view: average a chosen metric by n_cond. | |
| Usage: | |
| PYTHONPATH=src python scripts/aggregate.py [runs_dir] | |
| """ | |
| from __future__ import annotations | |
| import glob | |
| import json | |
| import os | |
| import sys | |
| from collections import defaultdict | |
| RUNS = sys.argv[1] if len(sys.argv) > 1 else "runs/full" | |
| HEADLINE = ["ndcg@10", "recall@10", "mrr@10", "recall@100"] | |
| def load_reports(runs_dir): | |
| # model -> benchmark -> list[report] | |
| out = defaultdict(lambda: defaultdict(list)) | |
| for path in glob.glob(os.path.join(runs_dir, "*", "*", "*.json")): | |
| if os.path.basename(path) == "summary.json": | |
| continue | |
| try: | |
| rep = json.load(open(path)) | |
| except Exception: | |
| continue | |
| if "dense" not in rep: | |
| continue | |
| model = path.split(os.sep)[-3] | |
| bench = rep.get("benchmark") or path.split(os.sep)[-2] | |
| out[model][bench].append(rep) | |
| return out | |
| def macro(reports, metric, stage="dense"): | |
| vals = [r[stage]["metrics"].get(metric) for r in reports if r.get(stage)] | |
| vals = [v for v in vals if v is not None] | |
| return sum(vals) / len(vals) if vals else None | |
| def fmt(v): | |
| return f"{v:.4f}" if isinstance(v, float) else " - " | |
| def main(): | |
| data = load_reports(RUNS) | |
| if not data: | |
| print(f"(no results yet under {RUNS})") | |
| return | |
| benches = sorted({b for m in data.values() for b in m}) | |
| models = sorted(data) | |
| for bench in benches: | |
| print(f"\n=== {bench} (macro over tasks) ===") | |
| print("model".ljust(12) + "".join(h.ljust(12) for h in HEADLINE) + "n_tasks") | |
| for m in models: | |
| reps = data[m].get(bench) | |
| if not reps: | |
| continue | |
| row = "".join(fmt(macro(reps, h)).ljust(12) for h in HEADLINE) | |
| print(m.ljust(12) + row + str(len(reps))) | |
| # stratified ndcg@10 by n_cond (MultiConIR / MERIT) | |
| print("\n=== ndcg@10 by #conditions ===") | |
| for bench in benches: | |
| dim = "n_cond" | |
| # collect per model: bucket -> [vals] | |
| per_model = {} | |
| for m in models: | |
| buckets = defaultdict(list) | |
| for r in data[m].get(bench, []): | |
| strat = r["dense"].get("stratified", {}).get(dim, {}) | |
| for k, mm in strat.items(): | |
| if mm.get("ndcg@10") is not None: | |
| buckets[k].append(mm["ndcg@10"]) | |
| if buckets: | |
| per_model[m] = {k: sum(v) / len(v) for k, v in buckets.items()} | |
| if not per_model: | |
| continue | |
| keys = sorted({k for d in per_model.values() for k in d}, key=lambda x: float(x)) | |
| print(f"\n[{bench}]") | |
| print("model".ljust(12) + "".join(str(k).ljust(8) for k in keys)) | |
| for m, d in per_model.items(): | |
| print(m.ljust(12) + "".join((f"{d[k]:.3f}" if k in d else " - ").ljust(8) for k in keys)) | |
| if __name__ == "__main__": | |
| main() | |