From 8bf7e9e770ced86fed9460919c0a6c254cecd8cb Mon Sep 17 00:00:00 2001 From: x Date: Thu, 3 Dec 2026 20:38:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(spatial):=20query=20token=20=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E5=8F=96=E6=8F=90=E9=97=AE=E5=AE=9E=E4=BD=93=E6=89=80?= =?UTF-8?q?=E8=BF=9E=E7=9A=84=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dof.set 单族训练的答案 loss 卡在 ln2(0.688),只有约 30 种不同场景也拟合不了。 原因在读出路径:query 的初值只有实体几何,轴向计数要经由注意力从 13 个位置里 平均出来,被稀释;而"六个轴是否全 lock"是六个逐轴阈值的合取,最怕这种平均。 现在 query 直接加上提问实体(两个端点)所连关系的袋和。这不是泄漏:问某个实体 的事,它的关联关系就是该取的证据,不该先过一道 softmax 才能到。 --- spatial/model.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spatial/model.py b/spatial/model.py index 159123b..a7e4091 100644 --- a/spatial/model.py +++ b/spatial/model.py @@ -151,6 +151,14 @@ class RelationBackbone(nn.Module): self.scene_proj = nn.Sequential(nn.Linear(SCENE_DIM, d), nn.GELU(), nn.Linear(d, d)) self.unk_tok = nn.Parameter(torch.zeros(d)) self.query_emb = nn.Embedding(len(QUERY_KINDS), d) + # the relations attached to the entity the question names, delivered to + # the question directly. Letting the query pick them up through attention + # means averaging them with a dozen unrelated positions, and "are all six + # axes locked" is a conjunction of six per-axis thresholds -- measured: at + # chance (0.49) even on a single family, with the training loss stuck at + # ln 2. The bag of incident relations is the evidence the question asks + # for; it should not have to survive a softmax to arrive. + self.q_inc = nn.Sequential(nn.Linear(d, d), nn.GELU(), nn.Linear(d, d)) self.edit_op_emb = nn.Embedding(3, d) # none / remove_edge / remove_entity # direction matters: a constraint points from the part to the fixture, a # conduct edge from source to sink. Two tables, not one symmetric table. @@ -334,6 +342,11 @@ class RelationBackbone(nn.Module): b_idx = q_ents[:, 1].clamp(min=0) q = q + torch.where(valid_a.unsqueeze(-1), h[ar, a_idx].unsqueeze(1), torch.zeros_like(q)) q = q + torch.where(valid_b.unsqueeze(-1), h[ar, b_idx].unsqueeze(1), torch.zeros_like(q)) + # and the relations hanging off those entities, without the detour + q = q + torch.where(valid_a.unsqueeze(-1), + self.q_inc(msg[ar, a_idx]).unsqueeze(1), torch.zeros_like(q)) + q = q + torch.where(valid_b.unsqueeze(-1), + self.q_inc(msg[ar, b_idx]).unsqueeze(1), torch.zeros_like(q)) # the intervention itself: which edge or entity the question removes if edit_op is not None and edit_idx is not None: