Datasets:
File size: 5,960 Bytes
a863f79 | 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 | import argparse
import glob
import json
from collections import defaultdict
from pathlib import Path
MODELS = ["qwen3vl", "qwen25vl", "idefics3", "internvl3", "molmo"]
CONDITIONS = ["T0", "Tpos", "Tneg", "Tabs", "Tunk"]
ROOT = Path("/mnt/f70f6709-366e-49a0-861f-497645d98975/lyz/GraphEvolve")
def load_jsonl(path):
with open(path, encoding="utf-8") as fh:
for line in fh:
line = line.strip()
if line:
yield json.loads(line)
def natural_truth():
truth = {}
for key, path in (
("spatialsense", ROOT / "runs/n_evidence_v1/gate0/source_manifest.jsonl"),
("vsr", ROOT / "runs/n_evidence_v1/gate3/manifest_vsr.jsonl"),
):
for row in load_jsonl(path):
truth[(key, row["annotation_id"])] = row["gold"]
return truth
def natural_table(truth, model):
stats = defaultdict(lambda: {"n": 0, "correct": 0, "yes": 0})
for path in sorted(glob.glob(str(ROOT / f"n_full_v1/predictions/natural/*_{model}_shard*.jsonl"))):
collection = Path(path).name.split("_")[0]
for row in load_jsonl(path):
gold = truth.get((collection, row["annotation_id"]))
if gold is None:
continue
cell = stats[(collection, row["condition"])]
cell["n"] += 1
cell["yes"] += int(row["answer"] == "yes")
cell["correct"] += int(row["answer"] == gold)
out = {}
for (collection, condition), cell in stats.items():
if condition not in CONDITIONS:
continue
out.setdefault(collection, {})[condition] = {
"n": cell["n"],
"acc": cell["correct"] / cell["n"] if cell["n"] else None,
"yes_rate": cell["yes"] / cell["n"] if cell["n"] else None,
}
return out
def synth_table(model):
path = ROOT / f"n_full_v1/analysis/synth_{model}.json"
if not path.exists():
return None
return json.loads(path.read_text(encoding="utf-8"))
def gate_table(model, split="test"):
path = ROOT / f"n_full_v1/analysis/vcg_{split}_{model}.json"
if not path.exists():
return None
return json.loads(path.read_text(encoding="utf-8"))
def fmt(value, digits=3):
if value is None:
return "—"
return f"{value:.{digits}f}"
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--out", default=str(ROOT / "n_full_v1/analysis/tables.md"))
args = parser.parse_args()
truth = natural_truth()
lines = []
synth = {}
for model in MODELS:
table = synth_table(model)
if table:
synth[model] = table
lines.append("# 合成域条件层与 V/T/K/R\n")
header = "| model | condition | n | acc | yes |"
lines.append(header)
lines.append("| --- | --- | ---: | ---: | ---: |")
for model, table in synth.items():
for condition in CONDITIONS:
cell = table["overall"]["conditions"].get(condition)
if not cell:
continue
lines.append(f"| {model} | {condition} | {cell['n']} | {fmt(cell['acc'])} | {fmt(cell['yes_rate'])} |")
lines.append("\n# 合成域 V/T/K/R 与端点\n")
lines.append("| model | V | T | K | R | FCA(T+) | FCA(T-) | TEU(T+) | TEU(T-) |")
lines.append("| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |")
for model, table in synth.items():
vtk = table["overall"]["vtk"]
lines.append(
"| {} | {} | {} | {} | {} | {} | {} | {} | {} |".format(
model,
fmt(vtk["v"]),
fmt(vtk["t"]),
fmt(vtk["k"]),
fmt(vtk["r"]),
fmt(table["overall"].get("fca_Tpos")),
fmt(table["overall"].get("fca_Tneg")),
fmt(table["overall"].get("teu_Tpos")),
fmt(table["overall"].get("teu_Tneg")),
)
)
lines.append("\n# 分族 V/T/K\n")
lines.append("| model | family | V | T | K | R |")
lines.append("| --- | --- | ---: | ---: | ---: | ---: |")
for model, table in synth.items():
for family, cell in table["by_family"].items():
vtk = cell["vtk"]
lines.append(
f"| {model} | {family} | {fmt(vtk['v'])} | {fmt(vtk['t'])} | {fmt(vtk['k'])} | {fmt(vtk['r'])} |"
)
lines.append("\n# 门控四方法(test)\n")
lines.append("| model | method | acc | coverage | induced | harm | repair |")
lines.append("| --- | --- | ---: | ---: | ---: | ---: | ---: |")
for model in MODELS:
gate = gate_table(model)
if not gate:
continue
for method in gate["methods"]:
lines.append(
"| {} | {} | {} | {} | {} | {} | {} |".format(
model,
method["method"],
fmt(method["accuracy"]),
fmt(method["coverage"]),
fmt(method["induced_error"]),
fmt(method["harm_rate"]),
fmt(method["repair_rate"]),
)
)
lines.append("\n# 自然域条件层\n")
lines.append("| model | collection | condition | n | acc | yes |")
lines.append("| --- | --- | --- | ---: | ---: | ---: |")
for model in MODELS:
table = natural_table(truth, model)
for collection in sorted(table):
for condition in CONDITIONS:
cell = table[collection].get(condition)
if not cell:
continue
lines.append(
f"| {model} | {collection} | {condition} | {cell['n']} | {fmt(cell['acc'])} | {fmt(cell['yes_rate'])} |"
)
out = Path(args.out)
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text("\n".join(lines) + "\n", encoding="utf-8")
print(f"WROTE {out} models={list(synth)}")
if __name__ == "__main__":
main()
|