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: