"""Render the mcr evaluation results into a self-contained HTML report. Reads runs/full///*.json, computes macro tables + multi-condition stratified curves, and emits a single HTML file with inline SVG charts (no external CDN, works offline). Usage: PYTHONNOUSERSITE=1 python scripts/make_report.py [runs_dir] [out_html] """ 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" OUT = sys.argv[2] if len(sys.argv) > 2 else "report.html" MODELS = ["emb-0.6B", "emb-4B", "emb-8B", "vl-2B", "vl-8B"] BENCH = ["multiconir", "mcmr", "ssrb_subset", "merit"] BENCH_LABEL = { "multiconir": "MultiConIR
散文·纯文本", "mcmr": "MCMR
文→图文", "ssrb_subset": "SSRB
JSON 半结构化", "merit": "MERIT
交错多图", } METRICS = ["ndcg@10", "recall@10", "mrr@10", "recall@100"] def load(): d = defaultdict(list) for p in glob.glob(os.path.join(RUNS, "*", "*", "*.json")): if p.endswith("summary.json"): continue try: r = json.load(open(p)) except Exception: continue if "dense" not in r: continue m = p.split(os.sep)[-3] b = p.split(os.sep)[-2] d[(m, b)].append(r) return d D = load() def macro(m, b, metric): reps = D.get((m, b), []) vs = [r["dense"]["metrics"].get(metric) for r in reps] vs = [x for x in vs if x is not None] return sum(vs) / len(vs) if vs else None def n_tasks(m, b): return len(D.get((m, b), [])) def strat(m, b, dim, metric="ndcg@10"): buck = defaultdict(list) for r in D.get((m, b), []): st = r["dense"].get("stratified", {}).get(dim, {}) for k, mm in st.items(): if mm.get(metric) is not None: buck[k].append(mm[metric]) return {k: sum(v) / len(v) for k, v in buck.items()} # ---------- HTML helpers ---------- def heat(v, lo, hi): """Green(high)->red(low) background for a value within [lo,hi].""" if v is None: return "background:#1b1f2a;color:#555" t = 0.0 if hi == lo else (v - lo) / (hi - lo) r = int(200 * (1 - t) + 40 * t) g = int(60 * (1 - t) + 170 * t) b = 70 return f"background:rgb({r},{g},{b});color:#fff" def matrix_table(metric): # per-column (benchmark) min/max for heat scaling cols = {} for b in BENCH: vals = [macro(m, b, metric) for m in MODELS] vals = [x for x in vals if x is not None] cols[b] = (min(vals), max(vals)) if vals else (0, 1) h = [''] for b in BENCH: h.append(f"") h.append("") for m in MODELS: h.append(f'') for b in BENCH: v = macro(m, b, metric) style = heat(v, *cols[b]) txt = f"{v:.3f}" if v is not None else "—" nt = n_tasks(m, b) sub = f'{nt}' if v is not None else "" h.append(f'') h.append("") h.append("
model{BENCH_LABEL[b]}
{m}{txt}{sub}
") return "".join(h) PALETTE = ["#e15759", "#f28e2b", "#edc948", "#59a14f", "#4e79a7"] def svg_line(series: dict, title: str, xlabel: str, width=560, height=300): """series: {name: {x(str-numeric): y}}; draws a line chart as inline SVG.""" xs = sorted({float(x) for s in series.values() for x in s}, key=float) if not xs: return f"

{title}: (no data)

" ys = [y for s in series.values() for y in s.values()] ymax = max(ys + [0.001]) ymax = (int(ymax / 0.1) + 1) * 0.1 # round up to 0.1 pad_l, pad_b, pad_t, pad_r = 48, 38, 36, 120 pw, ph = width - pad_l - pad_r, height - pad_b - pad_t def px(x): return pad_l + (xs.index(x) / max(1, len(xs) - 1)) * pw def py(y): return pad_t + ph - (y / ymax) * ph out = [f''] out.append(f'{title}') # y gridlines steps = 5 for i in range(steps + 1): yv = ymax * i / steps yy = py(yv) out.append(f'') out.append(f'{yv:.2f}') # x labels for x in xs: xx = px(x) out.append(f'{int(x)}') out.append(f'{xlabel}') # lines for i, (name, s) in enumerate(series.items()): col = PALETTE[i % len(PALETTE)] pts = [] for x in xs: key = str(int(x)) if str(int(x)) in s else (str(x) if str(x) in s else None) if key is None: continue pts.append((px(x), py(s[key]))) if not pts: continue d = "M" + " L".join(f"{a:.1f},{b:.1f}" for a, b in pts) out.append(f'') for a, b in pts: out.append(f'') ly = pad_t + 6 + i * 18 out.append(f'') out.append(f'{name}') out.append("") return "".join(out) # ---------- build sections ---------- ladder = [] for b in BENCH: best = max((macro(m, b, "ndcg@10") for m in MODELS if macro(m, b, "ndcg@10") is not None), default=None) ladder.append((b, best)) mc_curves = {m: {k: round(v, 3) for k, v in strat(m, "multiconir", "n_cond").items()} for m in MODELS} mc_curves = {m: s for m, s in mc_curves.items() if s} merit_curves = {m: strat(m, "merit", "n_cond") for m in ["vl-2B", "vl-8B"]} merit_curves = {m: s for m, s in merit_curves.items() if s} ssrb_curves = {m: strat(m, "ssrb_subset", "nf") for m in MODELS} ssrb_curves = {m: s for m, s in ssrb_curves.items() if s} scaling_rows = [] for b in BENCH: a, c = macro("vl-2B", b, "ndcg@10"), macro("vl-8B", b, "ndcg@10") if a and c: scaling_rows.append((b, a, c, (c - a) / a * 100)) html = f""" 多条件检索统一评测 · 结果报告

多条件检索统一评测 · 结果报告

框架 mcr · 4 benchmark × 5 模型(Qwen3-Embedding 0.6B/4B/8B · Qwen3-VL-Embedding 2B/8B)· 统一指标(自实现)· faiss 精确检索

MultiConIR 全量MCMR 全量 MERIT 全量(修复多图)SSRB 代表性子集 12 schema

① 总览矩阵 · ndcg@10

{matrix_table('ndcg@10')}

单元格内小数字 = 该格聚合的 task 数(域/schema)。颜色按 每个 benchmark 列内相对高低着色(各 benchmark 量级差异极大,不可跨列比色)。

② 难度阶梯(各 benchmark 最佳 ndcg@10)

{"".join(f'' for b,v in ladder)}
{b.replace("_subset","").upper()}
{(v or 0):.3f}
纯文本多条件(MultiConIR ~0.74)已接近解决;一旦进入跨模态(MCMR)→ 交错多图(MERIT)→ 半结构化大库(SSRB),性能跌一个数量级。

③ 规模 × 模态:scaling 收益随模态复杂度放大

{"".join(f'' for b,a,c,d in scaling_rows)}
benchmarkvl-2Bvl-8B相对提升
{b.replace("_subset","")}{a:.3f}{c:.3f}5 else "#8b949e"};font-weight:700">{d:+.0f}%
纯文本上堆参数几乎无用(MultiConIR ~0%);跨模态、多图多条件上大模型才真正拉开差距(MERIT +63%)。

④ 组合性衰减:性能随条件数下降

{svg_line(mc_curves, "MultiConIR · ndcg@10 vs 条件数", "条件数")}

全模型从 ~0.86(2 条件)单调跌到 ~0.47(10 条件),曲线高度重叠 → 与规模无关的普遍崩塌

{svg_line(ssrb_curves, "SSRB · ndcg@10 vs 过滤条件数 nf", "过滤条件数 nf")}

过滤条件越多越差;emb-4B 反超 emb-8B(非单调 scaling)。

{svg_line(merit_curves, "MERIT · ndcg@10 vs 条件数", "条件数", width=560, height=260)}

2 条件 0.14/0.22 → 3 条件骤降至 ~0.01。注意:3/4 条件样本极小(n=108 / n=5),该尾部统计上不稳。

⑤ 其它指标

recall@10

{matrix_table('recall@10')}

mrr@10

{matrix_table('mrr@10')}

recall@100

{matrix_table('recall@100')}

⑥ 说明与 caveat

  • SSRB 为代表性子集:6 域 × 各 2 schema = 12/99,非全量。
  • MERIT 多图已修复:query 经 ST message 模态编码,全部参考图参与(早期"首图近似"结果已废弃)。
  • MERIT 高条件桶样本小:2 条件 n≈9887 为主体;3/4 条件桶 n=108/5,尾部数值仅供参考。
  • 统一 query 指令、统一 faiss 精确检索;未做模型专属调优。MAP 采用 trec_eval map_cut 约定。
  • 指标自实现(不依赖 pytrec_eval),与手算/对拍一致。
""" with open(OUT, "w", encoding="utf-8") as f: f.write(html) print(f"wrote {OUT} ({len(html)} bytes)")