From dd906acf4b5c48c2e97098d60ad0c70546b7ef1a Mon Sep 17 00:00:00 2001 From: x Date: Thu, 3 Dec 2026 20:28:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(spatial):=20=E8=BE=B9=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=8A=A0=E4=B8=80=E6=9D=A1=E7=BA=BF=E6=80=A7=E9=80=9A=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "六个自由度轴是否全部被锁住"是关于集合基数的陈述,而非线性投影之和不再是计数: GELU 会把各个轴混在一起,袋和就丢掉了它到底见过哪几个轴。线性旁路让和保持为精确 的计数向量,一个阈值就能读出来。 --- spatial/model.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spatial/model.py b/spatial/model.py index bdc3c25..159123b 100644 --- a/spatial/model.py +++ b/spatial/model.py @@ -142,6 +142,12 @@ class RelationBackbone(nn.Module): self.ent_proj = nn.Sequential(nn.Linear(FEAT_DIM, d), nn.GELU(), nn.Linear(d, d)) self.edge_proj = nn.Sequential(nn.Linear(EDGE_FEAT_DIM, d), nn.GELU(), nn.Linear(d, d)) + # a linear path for edge content, alongside the nonlinear one. "Are all + # six axes locked" is a statement about the cardinality of a set, and the + # sum of a *nonlinear* projection of one-hots is no longer a count -- + # GELU mixes the axes and the bag loses which of them it saw. The linear + # skip keeps the sum an exact count vector, so a threshold can read it. + self.edge_lin = nn.Linear(EDGE_FEAT_DIM, d, bias=False) 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) @@ -318,7 +324,7 @@ class RelationBackbone(nn.Module): if edge_removed is not None: live = live & ~(edge_removed > 0) inc = inc * live.unsqueeze(1).to(inc.dtype) - msg = torch.bmm(inc, ef) + msg = torch.bmm(inc, ef) + torch.bmm(inc, self.edge_lin(edge_feat)) # query token is read out of the two entities it names q = self.query_emb(q_kind).unsqueeze(1).expand(B, 1, self.d).clone()