From 830bbac4f353ed924fc9bc37c378c76d8d5bc4c2 Mon Sep 17 00:00:00 2001 From: x Date: Thu, 3 Dec 2026 20:25:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(spatial):=20=E5=B7=B2=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E7=9A=84=E8=BE=B9=E4=B8=8D=E5=86=8D=E8=BF=9B=E5=85=A5=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E7=9A=84=E5=85=A5=E5=B0=84=E6=B1=82=E5=92=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 和 remove_entity 是同一类 bug:跳数已经按干预后的图算,但价值流里还在把被切断的 边加进端点。于是"删除 k0(tx 轴)"之后 P 的表示仍然报告 tx 被锁住,模型得先学会 把它减掉才能答对——自由度域的三种子抖动可能就来自这里。 --- spatial/model.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spatial/model.py b/spatial/model.py index a4d9af5..bdc3c25 100644 --- a/spatial/model.py +++ b/spatial/model.py @@ -303,7 +303,10 @@ class RelationBackbone(nn.Module): # backward pass simple and it makes "an entity receiving three edges sums # three vectors" obvious. Dangling edges are excluded: their far end is # not an entity, and pretending otherwise would credit an arbitrary node - # with a relation it does not have. + # with a relation it does not have. Removed edges are excluded too, for + # the same reason the hop distance excludes them: the question is about + # the graph after the cut, and an entity whose value still sums a cut + # constraint has to un-learn it before it can answer. inc = torch.zeros(B, n_ent, E, device=device) cols = torch.arange(E, device=device).view(1, E).expand(B, E) ones = torch.ones_like(cols, dtype=inc.dtype) @@ -311,7 +314,10 @@ class RelationBackbone(nn.Module): edge_index[..., 0].clamp(min=0, max=n_ent - 1), cols), ones) inc.index_put_((ar.unsqueeze(1).expand(B, E), edge_index[..., 1].clamp(min=0, max=n_ent - 1), cols), ones) - inc = inc * (edge_mask & ~has_unk).unsqueeze(1).to(inc.dtype) + live = edge_mask & ~has_unk + if edge_removed is not None: + live = live & ~(edge_removed > 0) + inc = inc * live.unsqueeze(1).to(inc.dtype) msg = torch.bmm(inc, ef) # query token is read out of the two entities it names