From f055851ac234944706d19ab477b753c6584a8002 Mon Sep 17 00:00:00 2001 From: lhj <403133128@qq.com> Date: Thu, 3 Dec 2026 19:15:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(spatial):=20=E6=82=AC=E7=A9=BA=E6=B6=88?= =?UTF-8?q?=E8=9E=8D=E8=A6=81=E5=90=8C=E6=97=B6=E6=B8=85=E6=8E=89=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E6=A7=BD=E4=BD=8D=E5=92=8C=E8=BE=B9=E4=B8=8A=E7=9A=84?= =?UTF-8?q?=E6=A0=87=E5=BF=97=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上一版只把 dangling 张量清零,边特征里的 dangling 位还在,于是"消融"测的是 另一条通路。现在 --ablate dangling 两处一起清,也可以传 dangling,scene 组合。 --- spatial/cli.py | 2 +- spatial/report.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/spatial/cli.py b/spatial/cli.py index 8999cb2..525033e 100644 --- a/spatial/cli.py +++ b/spatial/cli.py @@ -234,7 +234,7 @@ def main(argv=None) -> int: if name == "report": sp.add_argument("--n", type=int, default=128) sp.add_argument("--ablate", default=None, - choices=[None, "dangling", "scene", "edge_feat"]) + choices=[None, "dangling", "scene", "edge_feat", "dangling,scene"]) sp.set_defaults(fn=fn) args = p.parse_args(argv) return args.fn(args) diff --git a/spatial/report.py b/spatial/report.py index ed2bde3..768d55f 100644 --- a/spatial/report.py +++ b/spatial/report.py @@ -23,8 +23,11 @@ import torch from . import checker, generator from .data import collate +from .model import N_AXIS, N_EDGE from .train import load +DANGLING_BIT = N_EDGE + N_AXIS + 3 + ANSWERS = ("true", "false", "unknown") @@ -36,8 +39,16 @@ def family_row(model, family: str, seed: int, n: int, max_entities: int = 32, t = collate(batch, max_entities) t = {k: (v.to(device) if torch.is_tensor(v) else v) for k, v in t.items()} if ablate: - # a mechanism that survives its own removal was never used - t[ablate] = torch.zeros_like(t[ablate]) + # a mechanism that survives its own removal was never used. The dangling + # signal lives in two places -- the structural unknown slot and a flag on + # the edge itself -- so zeroing only one of them tests the other, not the + # mechanism. + for key in ablate.split(","): + if key == "dangling": + t["dangling"] = torch.zeros_like(t["dangling"]) + t["edge_feat"][..., DANGLING_BIT] = 0.0 + else: + t[key] = torch.zeros_like(t[key]) out = model(t["feat"], t["pad_mask"], t["edge_index"], t["edge_type"], t["edge_mask"], t["q_ents"], t["q_kind"], t["edit_op"], t["edit_idx"], t["edge_removed"], t["edge_feat"], t["scene"], t["dangling"])