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

+23 -1
View File
@@ -12,7 +12,7 @@ import torch
from collections import deque
from .schema import ANSWERS, CHANGES, DOF_AXES, EDGE_KINDS, ENTITY_KINDS, Scenario
from .model import EDGE_FEAT_DIM, FEAT_DIM, N_AXIS, N_EDGE, QUERY_KINDS
from .model import EDGE_FEAT_DIM, FEAT_DIM, N_AXIS, N_EDGE, QUERY_KINDS, SCENE_DIM
def _reach(edges, src: str, alive) -> set:
@@ -107,6 +107,25 @@ def edge_features(sc: Scenario, ed, removed: bool) -> list:
return f
def scene_features(sc: Scenario) -> list:
"""The observation's own admission of what it is missing.
``hidden_layers`` and ``hidden_faces`` are in the digest but were never in
the tensor, so "no hidden branch" and "a hidden branch off-view" arrived at
the model as the same input with opposite labels. That is not an
under-fitting problem; it is information the contract promised and the
tensorisation dropped.
"""
f = [0.0] * SCENE_DIM
for layer in sc.obs.hidden_layers:
if 1 <= layer <= 3:
f[layer - 1] = 1.0
f[3] = min(1.0, len(sc.obs.hidden_faces) / 6.0)
f[4] = 1.0 if (sc.obs.hidden_layers or sc.obs.hidden_faces) else 0.0
f[5] = len(sc.obs.entities) / 32.0
return f
def collate(batch, max_entities: int = 32):
B = len(batch)
N = max(1, max(len(sc.obs.entities) for sc in batch))
@@ -116,6 +135,7 @@ def collate(batch, max_entities: int = 32):
"bucket it instead of truncating")
feat = torch.zeros(B, N, FEAT_DIM)
scene = torch.zeros(B, SCENE_DIM)
pad_mask = torch.ones(B, N, dtype=torch.bool)
edge_index = torch.zeros(B, E, 2, dtype=torch.long)
edge_type = torch.zeros(B, E, dtype=torch.long)
@@ -132,6 +152,7 @@ def collate(batch, max_entities: int = 32):
for i, sc in enumerate(batch):
ids = {e.eid: j for j, e in enumerate(sc.obs.entities)}
scene[i] = torch.tensor(scene_features(sc))
for j, e in enumerate(sc.obs.entities):
feat[i, j] = torch.tensor(entity_features(sc, e))
pad_mask[i, j] = False
@@ -167,6 +188,7 @@ def collate(batch, max_entities: int = 32):
"feat": feat, "pad_mask": pad_mask,
"edge_index": edge_index, "edge_type": edge_type, "edge_mask": edge_mask,
"edge_feat": edge_feat,
"scene": scene,
"q_ents": q_ents, "q_kind": q_kind,
"edit_op": edit_op, "edit_idx": edit_idx,
"edge_removed": edge_removed,