Datasets:
Download code/make_tex_tables.py from spatial-evidence-bench/SpatialEvidenceBench: direct link, hf CLI and curl.
- Browser
- Download file 7.57 kB
-
https://huggingface.co/datasets/spatial-evidence-bench/SpatialEvidenceBench/resolve/main/code/make_tex_tables.py
- Command line
-
hf download hf://datasets/spatial-evidence-bench/SpatialEvidenceBench/code/make_tex_tables.py
-
curl -L -o make_tex_tables.py https://huggingface.co/datasets/spatial-evidence-bench/SpatialEvidenceBench/resolve/main/code/make_tex_tables.py
7.57 kB
| import json | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| OUT = Path("D:/GraphEvolve/docs/paper_v3/tables") | |
| MODELS = [("qwen3vl", "Qwen3-VL-8B"), ("qwen25vl", "Qwen2.5-VL-7B"), ("deepseekvl2s", "DeepSeek-VL2-Small")] | |
| CONDITIONS = [("T0", "T0"), ("Tpos", "T$+$"), ("Tneg", "T$-$"), ("Tabs", "T$\\varnothing$"), ("Tunk", "Tu")] | |
| FAMILIES = [("left_right", "left/right"), ("above_below", "above/below"), | |
| ("front_behind", "front/behind"), ("on_not_on", "on/not-on")] | |
| METHODS = [("direct_only", "Direct"), ("trust_all", "Trust-all"), ("vcg", "Gated"), | |
| ("vcg_support_only", "Gated-support"), ("vcg_confident", "Gated-conf"), | |
| ("witness_only", "Witness only"), ("independent_vlm_check", "Independent VLM")] | |
| def load(path): | |
| path = Path(path) | |
| return json.loads(path.read_text(encoding="utf-8")) if path.exists() else None | |
| def pct(value, digits=1): | |
| if value is None: | |
| return "--" | |
| return f"{value * 100:.{digits}f}" | |
| def write(name, text): | |
| OUT.mkdir(parents=True, exist_ok=True) | |
| (OUT / name).write_text(text, encoding="utf-8") | |
| print(f"WROTE {name}") | |
| def tab_conditions(): | |
| lines = [ | |
| r"\begin{tabular}{llccccc}", | |
| r"\toprule", | |
| r"Model & Metric & T0 & T$+$ & T$-$ & T$\varnothing$ & Tu \\", | |
| r"\midrule", | |
| ] | |
| for key, label in MODELS: | |
| table = load(ROOT / f"analysis/synth_{key}.json") | |
| if not table: | |
| continue | |
| acc = [pct(table["overall"]["conditions"][c]["acc"]) for c, _ in CONDITIONS] | |
| yes = [pct(table["overall"]["conditions"][c]["yes_rate"]) for c, _ in CONDITIONS] | |
| lines.append(f"{label} & acc. & " + " & ".join(acc) + r" \\") | |
| lines.append(f" & yes & " + " & ".join(yes) + r" \\") | |
| lines.append(r"\addlinespace[2pt]") | |
| lines += [r"\bottomrule", r"\end{tabular}"] | |
| write("tab_conditions.tex", "\n".join(lines) + "\n") | |
| def tab_vtk(): | |
| lines = [ | |
| r"\begin{tabular}{lccccccccc}", | |
| r"\toprule", | |
| r"Model & V & T & K & R & PFC & FCA(T$+$) & FCA(T$-$) & TEU(T$+$) & TEU(T$-$) \\", | |
| r"\midrule", | |
| ] | |
| for key, label in MODELS: | |
| table = load(ROOT / f"analysis/synth_{key}.json") | |
| if not table: | |
| continue | |
| vtk = table["overall"]["vtk"] | |
| cells = [pct(vtk["v"]), pct(vtk["t"]), pct(vtk["k"]), pct(vtk["r"]), | |
| pct(table["overall"].get("pfc")), | |
| pct(table["overall"].get("fca_Tpos")), pct(table["overall"].get("fca_Tneg")), | |
| pct(table["overall"].get("teu_Tpos")), pct(table["overall"].get("teu_Tneg"))] | |
| lines.append(f"{label} & " + " & ".join(cells) + r" \\") | |
| lines += [r"\bottomrule", r"\end{tabular}"] | |
| write("tab_vtk.tex", "\n".join(lines) + "\n") | |
| def tab_family(): | |
| lines = [ | |
| r"\begin{tabular}{llcccc}", | |
| r"\toprule", | |
| r"Model & Family & V & T & K & R \\", | |
| r"\midrule", | |
| ] | |
| for key, label in MODELS: | |
| table = load(ROOT / f"analysis/synth_{key}.json") | |
| if not table: | |
| continue | |
| for fam, fam_label in FAMILIES: | |
| vtk = table["by_family"][fam]["vtk"] | |
| lines.append( | |
| f"{label} & {fam_label} & {pct(vtk['v'])} & {pct(vtk['t'])} & {pct(vtk['k'])} & {pct(vtk['r'])} \\\\" | |
| ) | |
| lines.append(r"\addlinespace[2pt]") | |
| lines += [r"\bottomrule", r"\end{tabular}"] | |
| write("tab_family.tex", "\n".join(lines) + "\n") | |
| def tab_gate(): | |
| lines = [ | |
| r"\begin{tabular}{lcccccc}", | |
| r"\toprule", | |
| r"Model & Method & Acc. & Cov. & Induced & Harm & Repair \\", | |
| r"\midrule", | |
| ] | |
| for key, label in MODELS: | |
| table = load(ROOT / f"analysis/vcg_test_{key}.json") | |
| if not table: | |
| continue | |
| lookup = {m["method"]: m for m in table["methods"]} | |
| for method, method_label in METHODS: | |
| cell = lookup.get(method) | |
| if not cell: | |
| continue | |
| lines.append( | |
| f"{label} & {method_label} & {pct(cell['accuracy'])} & {pct(cell['coverage'])} & " | |
| f"{pct(cell['induced_error'])} & {pct(cell['harm_rate'])} & {pct(cell['repair_rate'])} \\\\" | |
| ) | |
| lines.append(r"\addlinespace[2pt]") | |
| lines += [r"\bottomrule", r"\end{tabular}"] | |
| write("tab_gate.tex", "\n".join(lines) + "\n") | |
| def tab_natural(): | |
| lines = [ | |
| r"\begin{tabular}{llccccc}", | |
| r"\toprule", | |
| r"Model & Collection & T0 & T$+$ & T$-$ & T$\varnothing$ & Tu \\", | |
| r"\midrule", | |
| ] | |
| for key, label in MODELS: | |
| cells = {} | |
| base = Path(f"/mnt/f70f6709-366e-49a0-861f-497645d98975/lyz/GraphEvolve/n_full_v1/predictions/natural") | |
| for collection in ("spatialsense", "vsr"): | |
| table = load(ROOT / f"analysis/natural_{key}_{collection}.json") | |
| if table: | |
| cells[collection] = table | |
| if not cells: | |
| continue | |
| for collection, data in cells.items(): | |
| row = [pct(data[c]["acc"]) for c, _ in CONDITIONS] | |
| lines.append(f"{label} & {collection} & " + " & ".join(row) + r" \\") | |
| lines.append(r"\addlinespace[2pt]") | |
| lines += [r"\bottomrule", r"\end{tabular}"] | |
| write("tab_natural.tex", "\n".join(lines) + "\n") | |
| def tab_gate_family(): | |
| lines = [ | |
| r"\begin{tabular}{llccccc}", | |
| r"\toprule", | |
| r"Model & Family & Direct & Trust-all & Support-only & Support & Refute \\", | |
| r"\midrule", | |
| ] | |
| for key, label in MODELS: | |
| table = load(ROOT / f"analysis/vcg_test_{key}.json") | |
| if not table: | |
| continue | |
| for family in ("above_below", "front_behind", "left_right", "on_not_on"): | |
| cell = table["by_family"].get(family) | |
| if not cell: | |
| continue | |
| family_label = dict(FAMILIES)[family] | |
| lines.append( | |
| f"{label} & {family_label} & {pct(cell['direct_only'])} & {pct(cell['trust_all'])} & " | |
| f"{pct(cell['vcg_support_only'])} & {pct(cell.get('support_rate'))} & {pct(cell.get('refute_rate'))} \\\\" | |
| ) | |
| lines.append(r"\addlinespace[2pt]") | |
| lines += [r"\bottomrule", r"\end{tabular}"] | |
| write("tab_gate_family.tex", "\n".join(lines) + "\n") | |
| def pct_ci(point, ci, digits=1): | |
| if point is None: | |
| return "--" | |
| if not ci: | |
| return pct(point, digits) | |
| return f"{point * 100:.{digits}f} [{ci['lo'] * 100:.{digits}f}, {ci['hi'] * 100:.{digits}f}]" | |
| def tab_ci(): | |
| lines = [ | |
| r"\begin{tabular}{lcccccc}", | |
| r"\toprule", | |
| r"Model & V & T & K & R & FCA(T$+$) & TEU(T$+$) \\", | |
| r"\midrule", | |
| ] | |
| for key, label in MODELS: | |
| table = load(ROOT / f"analysis/synth_{key}.json") | |
| boot = load(ROOT / f"analysis/boot_{key}.json") | |
| if not table or not boot: | |
| continue | |
| point = boot["point"] | |
| ci = boot["ci"] | |
| cells = [pct_ci(point["v"], ci.get("v")), pct_ci(point["t"], ci.get("t")), | |
| pct_ci(point["k"], ci.get("k")), pct_ci(point["r"], ci.get("r")), | |
| pct_ci(point["fca_Tpos"], ci.get("fca_Tpos")), | |
| pct_ci(point["teu_Tpos"], ci.get("teu_Tpos"))] | |
| lines.append(f"{label} & " + " & ".join(cells) + r" \\\\") | |
| lines += [r"\bottomrule", r"\end{tabular}"] | |
| write("tab_ci.tex", "\n".join(lines) + "\n") | |
| def main(): | |
| tab_conditions() | |
| tab_vtk() | |
| tab_family() | |
| tab_gate() | |
| tab_gate_family() | |
| tab_natural() | |
| tab_ci() | |
| if __name__ == "__main__": | |
| main() | |