#!/usr/bin/env python3 """Score-vs-latency scatter for the model card. Self-contained SVG, no deps.""" # honest held-out (500 fresh zh-TW sentences) + BOOX (SD662) per-6-syllable decode ms # latency: 4M/12M measured (ORT int8); 25M ternary projected from measured-shape # bitnet TQ2_0/I2_S kernel benchmarks (marked with *). MODELS = [ # name, params, latency_ms, proj, mianxuan, homophone, toneless, color ("4M int8", "4M", 9.06, False, 70, 83, 74, "#6b7280"), ("12M int8", "12M", 13.3, False, 72, 82, 79, "#2563eb"), ("25M ternary", "25M", 9.0, True, 76, 86, 77, "#dc2626"), ] W, H = 680, 440 L, R, T, B = 74, 28, 46, 66 # margins PX0, PX1 = L, W - R PY0, PY1 = T, H - B XMIN, XMAX = 8.0, 14.5 YMIN, YMAX = 66.0, 80.0 def x(v): return PX0 + (v - XMIN) / (XMAX - XMIN) * (PX1 - PX0) def y(v): return PY1 - (v - YMIN) / (YMAX - YMIN) * (PY1 - PY0) s = [] s.append(f'') # always-light background card so it reads on both HF themes s.append(f'') s.append(f'' f'Held-out quality vs. on-device latency (BOOX SD662)') # gridlines + y ticks (免選字 %) for yv in range(66, 81, 2): yy = y(yv) s.append(f'') s.append(f'{yv}') # x ticks (ms) for xv in range(8, 15, 1): xx = x(xv) s.append(f'') s.append(f'{xv}') # axis labels s.append(f'latency — ms / 6-syllable decode (lower = faster)') s.append(f'' f'免選字 (whole-sentence) % (higher = better)') # axis frame s.append(f'') # Pareto arrow: 4M -> 25M ternary (up, same latency), the headline story s.append(f'') # points for name, tag, lat, proj, mx, ho, tl, col in MODELS: cx, cy = x(lat), y(mx) s.append(f'') star = "*" if proj else "" # two-line label fully above the point (name higher, stats just above point), # except 4M which sits low so its label goes below the point. if name == "4M int8": name_y, sub_y = cy + 24, cy + 39 else: name_y, sub_y = cy - 30, cy - 14 s.append(f'{name}{star}') s.append(f'免{mx} · 同{ho} · 無{tl}') # projection note under the title (avoids the crowded bottom axis area) s.append(f'' f'* 25M ternary latency projected from measured-shape TQ2_0 / I2_S kernels') s.append('') open("score_vs_latency.svg", "w").write("\n".join(s)) print("wrote score_vs_latency.svg")