File size: 12,427 Bytes
cbb33d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
"""Render the mcr evaluation results into a self-contained HTML report.

Reads runs/full/<model>/<benchmark>/*.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<br><small>散文·纯文本</small>",
    "mcmr": "MCMR<br><small>文→图文</small>",
    "ssrb_subset": "SSRB<br><small>JSON 半结构化</small>",
    "merit": "MERIT<br><small>交错多图</small>",
}
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 = ['<table class="mat"><thead><tr><th>model</th>']
    for b in BENCH:
        h.append(f"<th>{BENCH_LABEL[b]}</th>")
    h.append("</tr></thead><tbody>")
    for m in MODELS:
        h.append(f'<tr><td class="mname">{m}</td>')
        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'<span class="nt">{nt}</span>' if v is not None else ""
            h.append(f'<td style="{style}">{txt}{sub}</td>')
        h.append("</tr>")
    h.append("</tbody></table>")
    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"<p>{title}: (no data)</p>"
    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'<svg viewBox="0 0 {width} {height}" class="chart">']
    out.append(f'<text x="{width/2}" y="18" class="ctitle" text-anchor="middle">{title}</text>')
    # y gridlines
    steps = 5
    for i in range(steps + 1):
        yv = ymax * i / steps
        yy = py(yv)
        out.append(f'<line x1="{pad_l}" y1="{yy:.1f}" x2="{pad_l+pw}" y2="{yy:.1f}" class="grid"/>')
        out.append(f'<text x="{pad_l-6}" y="{yy+3:.1f}" class="axlbl" text-anchor="end">{yv:.2f}</text>')
    # x labels
    for x in xs:
        xx = px(x)
        out.append(f'<text x="{xx:.1f}" y="{pad_t+ph+16:.1f}" class="axlbl" text-anchor="middle">{int(x)}</text>')
    out.append(f'<text x="{pad_l+pw/2:.1f}" y="{height-4}" class="axlbl" text-anchor="middle">{xlabel}</text>')
    # 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'<path d="{d}" fill="none" stroke="{col}" stroke-width="2.2"/>')
        for a, b in pts:
            out.append(f'<circle cx="{a:.1f}" cy="{b:.1f}" r="3" fill="{col}"/>')
        ly = pad_t + 6 + i * 18
        out.append(f'<line x1="{pad_l+pw+12}" y1="{ly}" x2="{pad_l+pw+30}" y2="{ly}" stroke="{col}" stroke-width="3"/>')
        out.append(f'<text x="{pad_l+pw+34}" y="{ly+4}" class="leg">{name}</text>')
    out.append("</svg>")
    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"""<!DOCTYPE html>
<html lang="zh"><head><meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>多条件检索统一评测 · 结果报告</title>
<style>
:root{{--bg:#0e1117;--card:#161b22;--ink:#e6edf3;--mut:#8b949e;--line:#30363d;--acc:#58a6ff;}}
*{{box-sizing:border-box}}
body{{margin:0;background:var(--bg);color:var(--ink);font:15px/1.6 -apple-system,'Segoe UI',Roboto,'PingFang SC','Microsoft YaHei',sans-serif}}
.wrap{{max-width:1040px;margin:0 auto;padding:32px 20px 80px}}
h1{{font-size:26px;margin:0 0 4px}} h2{{font-size:19px;margin:34px 0 12px;padding-bottom:6px;border-bottom:1px solid var(--line)}}
.sub{{color:var(--mut);margin:0 0 20px}}
.card{{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:18px 20px;margin:14px 0}}
table{{border-collapse:collapse;width:100%;font-variant-numeric:tabular-nums}}
.mat th,.mat td{{padding:9px 10px;text-align:center;border:1px solid var(--line)}}
.mat th{{background:#1b2230;color:var(--ink);font-weight:600;font-size:13px}}
.mat td{{font-weight:600}} .mname{{text-align:left!important;background:#1b2230;color:var(--acc);font-family:ui-monospace,monospace}}
.nt{{display:block;font-size:10px;opacity:.7;font-weight:400}}
small{{color:var(--mut);font-weight:400}}
.kv{{padding:8px 10px;border:1px solid var(--line);text-align:center}}
.chart{{width:100%;height:auto;background:#0d1117;border-radius:8px;margin:6px 0}}
.ctitle{{fill:var(--ink);font-size:14px;font-weight:600}}
.grid{{stroke:#222b38;stroke-width:1}} .axlbl{{fill:var(--mut);font-size:11px}} .leg{{fill:var(--ink);font-size:11px;font-family:ui-monospace,monospace}}
.note{{color:var(--mut);font-size:13px}}
.find{{border-left:3px solid var(--acc);padding:4px 0 4px 14px;margin:12px 0}}
.grid2{{display:grid;grid-template-columns:1fr 1fr;gap:14px}} @media(max-width:760px){{.grid2{{grid-template-columns:1fr}}}}
.pill{{display:inline-block;background:#1b2230;border:1px solid var(--line);border-radius:999px;padding:2px 10px;font-size:12px;color:var(--mut);margin-right:6px}}
</style></head><body><div class="wrap">

<h1>多条件检索统一评测 · 结果报告</h1>
<p class="sub">框架 <code>mcr</code> · 4 benchmark × 5 模型(Qwen3-Embedding 0.6B/4B/8B · Qwen3-VL-Embedding 2B/8B)·
统一指标(自实现)· faiss 精确检索</p>
<div>
<span class="pill">MultiConIR 全量</span><span class="pill">MCMR 全量</span>
<span class="pill">MERIT 全量(修复多图)</span><span class="pill">SSRB 代表性子集 12 schema</span>
</div>

<h2>① 总览矩阵 · ndcg@10</h2>
<div class="card">{matrix_table('ndcg@10')}
<p class="note">单元格内小数字 = 该格聚合的 task 数(域/schema)。颜色按 <b>每个 benchmark 列</b>内相对高低着色(各 benchmark 量级差异极大,不可跨列比色)。</p></div>

<h2>② 难度阶梯(各 benchmark 最佳 ndcg@10)</h2>
<div class="card">
<table><tr>{"".join(f'<td class="kv"><div style="color:var(--mut);font-size:12px">{b.replace("_subset","").upper()}</div><div style="font-size:22px;font-weight:700;color:var(--acc)">{(v or 0):.3f}</div></td>' for b,v in ladder)}</tr></table>
<div class="find">纯文本多条件(MultiConIR ~0.74)已接近解决;一旦进入<b>跨模态(MCMR)→ 交错多图(MERIT)→ 半结构化大库(SSRB)</b>,性能跌一个数量级。</div>
</div>

<h2>③ 规模 × 模态:scaling 收益随模态复杂度放大</h2>
<div class="card">
<table class="mat"><thead><tr><th>benchmark</th><th>vl-2B</th><th>vl-8B</th><th>相对提升</th></tr></thead><tbody>
{"".join(f'<tr><td class="mname">{b.replace("_subset","")}</td><td>{a:.3f}</td><td>{c:.3f}</td><td style="color:{"#59a14f" if d>5 else "#8b949e"};font-weight:700">{d:+.0f}%</td></tr>' for b,a,c,d in scaling_rows)}
</tbody></table>
<div class="find">纯文本上堆参数几乎无用(MultiConIR ~0%);<b>跨模态、多图多条件上大模型才真正拉开差距</b>(MERIT +63%)。</div>
</div>

<h2>④ 组合性衰减:性能随条件数下降</h2>
<div class="grid2">
<div class="card">{svg_line(mc_curves, "MultiConIR · ndcg@10 vs 条件数", "条件数")}
<p class="note">全模型从 ~0.86(2 条件)单调跌到 ~0.47(10 条件),曲线高度重叠 → <b>与规模无关的普遍崩塌</b>。</p></div>
<div class="card">{svg_line(ssrb_curves, "SSRB · ndcg@10 vs 过滤条件数 nf", "过滤条件数 nf")}
<p class="note">过滤条件越多越差;<b>emb-4B 反超 emb-8B</b>(非单调 scaling)。</p></div>
</div>
<div class="card">{svg_line(merit_curves, "MERIT · ndcg@10 vs 条件数", "条件数", width=560, height=260)}
<p class="note">2 条件 0.14/0.22 → 3 条件骤降至 ~0.01。<b>注意</b>:3/4 条件样本极小(n=108 / n=5),该尾部统计上不稳。</p></div>

<h2>⑤ 其它指标</h2>
<div class="grid2">
<div class="card"><h3 style="margin:0 0 8px;font-size:15px">recall@10</h3>{matrix_table('recall@10')}</div>
<div class="card"><h3 style="margin:0 0 8px;font-size:15px">mrr@10</h3>{matrix_table('mrr@10')}</div>
</div>
<div class="card"><h3 style="margin:0 0 8px;font-size:15px">recall@100</h3>{matrix_table('recall@100')}</div>

<h2>⑥ 说明与 caveat</h2>
<div class="card note">
<ul>
<li><b>SSRB 为代表性子集</b>:6 域 × 各 2 schema = 12/99,非全量。</li>
<li><b>MERIT 多图已修复</b>:query 经 ST <code>message</code> 模态编码,全部参考图参与(早期"首图近似"结果已废弃)。</li>
<li><b>MERIT 高条件桶样本小</b>:2 条件 n≈9887 为主体;3/4 条件桶 n=108/5,尾部数值仅供参考。</li>
<li>统一 query 指令、统一 faiss 精确检索;未做模型专属调优。MAP 采用 trec_eval map_cut 约定。</li>
<li>指标自实现(不依赖 pytrec_eval),与手算/对拍一致。</li>
</ul>
</div>

</div></body></html>"""

with open(OUT, "w", encoding="utf-8") as f:
    f.write(html)
print(f"wrote {OUT} ({len(html)} bytes)")