fix(spatial): 补上"观测自己承认缺失了什么"的输入,cond.p1/cond.p1h 不再是同一张量

hidden_layers 和 hidden_faces 一直只在 digest 里,没进过张量。于是
"不存在隐藏支路"和"有隐藏支路但在视野外"到达模型时是同一个输入、标签却相反
(前者 false,后者 unknown)。这不是欠拟合,是契约承诺了、张量化却丢掉了的信息。

现在把观测的"缺失声明"投影到 query token 上:隐藏层 1..3 指示位、未见面的数量、
"确有东西被隐藏"一位、场景规模。模型因此有机会说"我看不到决定这件事的那部分"。
This commit is contained in:
liuhuajie committed 2026-12-03 18:31:25 +08:00
1 parent 1e0dcd6fb4
commit 08153b987d
4 files changed
+38 -4

No files matched your search

+13 -1
View File
@@ -45,6 +45,11 @@ QUERY_KINDS = ("connection", "stability", "freedom")
HOP_MAX = 4 # longer paths collapse into one bucket
FAR = HOP_MAX + 1 # unreachable, or "involves the query token"
# what the observation admits it is missing: hidden layer markers, unseen faces,
# and one bit for "something was withheld at all". Without this the two worlds
# "no hidden branch exists" and "a hidden branch exists off-view" are literally
# the same tensor, and no amount of reasoning can separate them.
SCENE_DIM = 6
def hop_distance(edge_index, edge_mask, edge_removed, n_ent: int) -> torch.Tensor:
@@ -125,6 +130,7 @@ 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))
self.scene_proj = nn.Sequential(nn.Linear(SCENE_DIM, d), nn.GELU(), nn.Linear(d, d))
self.query_emb = nn.Embedding(len(QUERY_KINDS), 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
@@ -237,7 +243,7 @@ class RelationBackbone(nn.Module):
# ------------------------------------------------------------------
def forward(self, feat, pad_mask, edge_index, edge_type, edge_mask, q_ents, q_kind,
edit_op=None, edit_idx=None, edge_removed=None, edge_feat=None):
edit_op=None, edit_idx=None, edge_removed=None, edge_feat=None, scene=None):
B, n_ent, _ = feat.shape
E = edge_index.size(1)
device = feat.device
@@ -284,6 +290,12 @@ class RelationBackbone(nn.Module):
has = (edit_op > 0).unsqueeze(-1).to(q.dtype)
q = q + self.edit_op_emb(edit_op).unsqueeze(1) + (tgt * has).unsqueeze(1)
# what the observation says it cannot see is part of the question, not a
# property of any entity, so it rides on the query token where every
# entity can attend to it
if scene is not None:
q = q + self.scene_proj(scene).unsqueeze(1)
zeros_ev = torch.zeros(B, K, self.d, device=device)
x_tok = torch.cat([q, h, zeros_ev], dim=1) # (B, 1+N+K, d)
v_extra = torch.cat([torch.zeros(B, 1, self.d, device=device), msg, zeros_ev], dim=1)