Datasets:
Download code/make_figs.py from spatial-evidence-bench/SpatialEvidenceBench: direct link, hf CLI and curl.
- Browser
- Download file 5.24 kB
-
https://huggingface.co/datasets/spatial-evidence-bench/SpatialEvidenceBench/resolve/81ec431b4e89dd554f2e9ee6ee04e3e137bca476/code/make_figs.py
- Command line
-
hf download hf://datasets/spatial-evidence-bench/SpatialEvidenceBench@81ec431b4e89dd554f2e9ee6ee04e3e137bca476/code/make_figs.py
-
curl -L -o make_figs.py https://huggingface.co/datasets/spatial-evidence-bench/SpatialEvidenceBench/resolve/81ec431b4e89dd554f2e9ee6ee04e3e137bca476/code/make_figs.py
5.24 kB
| import json | |
| from pathlib import Path | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import sys | |
| sys.path.insert(0, str(Path("D:/GraphEvolve/figures_workspace/_utils"))) | |
| import plot_utils as pu | |
| ROOT = Path(__file__).resolve().parents[1] | |
| OUT = ROOT / "figures" | |
| CONDITIONS = ["T0", "Tpos", "Tneg", "Tabs", "Tunk"] | |
| LABELS = {"T0": "T0", "Tpos": "T+", "Tneg": "T-", "Tabs": "T∅", "Tunk": "Tu"} | |
| MODELS = [("qwen3vl", "Qwen3-VL-8B"), ("qwen25vl", "Qwen2.5-VL-7B"), ("deepseekvl2s", "DeepSeek-VL2-Small")] | |
| FAMILIES = {"left_right": "left/right", "above_below": "above/below", | |
| "front_behind": "front/behind", "on_not_on": "on/not-on"} | |
| def load(path): | |
| return json.loads(Path(path).read_text(encoding="utf-8")) | |
| def synth(model): | |
| path = ROOT / f"analysis/synth_{model}.json" | |
| return load(path) if path.exists() else None | |
| def gate(model): | |
| path = ROOT / f"analysis/vcg_test_{model}.json" | |
| return load(path) if path.exists() else None | |
| def colors(n): | |
| keys = ["primary", "secondary", "accent", "highlight", "light"] | |
| return [pu.COLORS[keys[i % len(keys)]] for i in range(n)] | |
| def fig_conditions(models): | |
| fig, axes = plt.subplots(1, 2, figsize=(7.0, 2.6)) | |
| width = 0.8 / len(models) | |
| xs = np.arange(len(CONDITIONS)) | |
| for ax, key, title in ((axes[0], "acc", "Accuracy"), (axes[1], "yes_rate", "Yes rate")): | |
| for i, (model, label) in enumerate(models): | |
| table = synth(model) | |
| if not table: | |
| continue | |
| vals = [table["overall"]["conditions"][c][key] for c in CONDITIONS] | |
| ax.bar(xs + i * width - 0.4 + width / 2, vals, width, label=label, color=colors(len(models))[i]) | |
| ax.set_xticks(xs) | |
| ax.set_xticklabels([LABELS[c] for c in CONDITIONS]) | |
| ax.set_ylim(0, 1) | |
| ax.set_title(title, fontsize=9) | |
| ax.grid(axis="y", alpha=0.25) | |
| axes[0].set_ylabel("value") | |
| axes[0].legend(frameon=False, fontsize=7, loc="lower left") | |
| fig.tight_layout() | |
| pu._save(fig, str(OUT / "fig_conditions.pdf")) | |
| plt.close(fig) | |
| def fig_vtk(models): | |
| fig, ax = plt.subplots(figsize=(6.4, 2.4)) | |
| metrics = ["v", "t", "k", "r"] | |
| names = ["V", "T", "K", "R"] | |
| width = 0.8 / len(models) | |
| xs = np.arange(len(metrics)) | |
| for i, (model, label) in enumerate(models): | |
| table = synth(model) | |
| if not table: | |
| continue | |
| vtk = table["overall"]["vtk"] | |
| vals = [vtk[m] for m in metrics] | |
| ax.bar(xs + i * width - 0.4 + width / 2, vals, width, label=label, color=colors(len(models))[i]) | |
| ax.axhline(0, color="0.3", lw=0.6) | |
| ax.set_xticks(xs) | |
| ax.set_xticklabels(names) | |
| ax.set_ylabel("value") | |
| ax.grid(axis="y", alpha=0.25) | |
| ax.legend(frameon=False, fontsize=7, ncol=3, loc="upper right") | |
| fig.tight_layout() | |
| pu._save(fig, str(OUT / "fig_vtk.pdf")) | |
| plt.close(fig) | |
| def fig_family(models): | |
| fig, axes = plt.subplots(1, len(models), figsize=(7.0, 2.2), sharey=True) | |
| fams = list(FAMILIES) | |
| for ax, (model, label) in zip(np.atleast_1d(axes), models): | |
| table = synth(model) | |
| if not table: | |
| continue | |
| v = [table["by_family"][f]["vtk"]["v"] for f in fams] | |
| t = [table["by_family"][f]["vtk"]["t"] for f in fams] | |
| xs = np.arange(len(fams)) | |
| ax.bar(xs - 0.19, v, 0.36, label="V", color=colors(2)[0]) | |
| ax.bar(xs + 0.19, t, 0.36, label="T", color=colors(2)[1]) | |
| ax.set_xticks(xs) | |
| ax.set_xticklabels([FAMILIES[f] for f in fams], rotation=18, fontsize=6, ha="right") | |
| ax.set_title(label, fontsize=7) | |
| ax.set_ylim(0, 1) | |
| ax.grid(axis="y", alpha=0.25) | |
| np.atleast_1d(axes)[0].set_ylabel("value") | |
| np.atleast_1d(axes)[0].legend(frameon=False, fontsize=6) | |
| fig.tight_layout() | |
| pu._save(fig, str(OUT / "fig_family.pdf")) | |
| plt.close(fig) | |
| def fig_gate(models): | |
| methods = ["direct_only", "trust_all", "vcg", "vcg_support_only", "vcg_confident"] | |
| names = ["direct", "trust-all", "gated", "gated-support", "gated-conf"] | |
| fig, ax = plt.subplots(figsize=(6.2, 2.4)) | |
| width = 0.8 / len(models) | |
| xs = np.arange(len(methods)) | |
| for i, (model, label) in enumerate(models): | |
| table = gate(model) | |
| if not table: | |
| continue | |
| lookup = {m["method"]: m["accuracy"] for m in table["methods"]} | |
| vals = [lookup[m] for m in methods] | |
| ax.bar(xs + i * width - 0.4 + width / 2, vals, width, label=label, color=colors(len(models))[i]) | |
| ax.set_xticks(xs) | |
| ax.set_xticklabels(names, fontsize=7) | |
| ax.set_ylim(0.4, 0.9) | |
| ax.set_ylabel("accuracy") | |
| ax.grid(axis="y", alpha=0.25) | |
| ax.legend(frameon=False, fontsize=6, ncol=3) | |
| fig.tight_layout() | |
| pu._save(fig, str(OUT / "fig_gate.pdf")) | |
| plt.close(fig) | |
| def main(): | |
| OUT.mkdir(parents=True, exist_ok=True) | |
| pu.setup_style(palette="olive-apricot", language="en", font_family=["Arial", "DejaVu Sans"]) | |
| models = [(m, l) for m, l in MODELS if synth(m)] | |
| if not models: | |
| raise RuntimeError("no synthetic results yet") | |
| fig_conditions(models) | |
| fig_vtk(models) | |
| fig_family(models) | |
| fig_gate(models) | |
| print(f"WROTE figures for {[m for m, _ in models]}") | |
| if __name__ == "__main__": | |
| main() | |