feat(spatial): query token 直接取提问实体所连的关系
dof.set 单族训练的答案 loss 卡在 ln2(0.688),只有约 30 种不同场景也拟合不了。 原因在读出路径:query 的初值只有实体几何,轴向计数要经由注意力从 13 个位置里 平均出来,被稀释;而"六个轴是否全 lock"是六个逐轴阈值的合取,最怕这种平均。 现在 query 直接加上提问实体(两个端点)所连关系的袋和。这不是泄漏:问某个实体 的事,它的关联关系就是该取的证据,不该先过一道 softmax 才能到。
This commit is contained in:
1 parent
0390afb932
commit
8bf7e9e770
1 file changed
+13
@@ -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.scene_proj = nn.Sequential(nn.Linear(SCENE_DIM, d), nn.GELU(), nn.Linear(d, d))
|
||||||
self.unk_tok = nn.Parameter(torch.zeros(d))
|
self.unk_tok = nn.Parameter(torch.zeros(d))
|
||||||
self.query_emb = nn.Embedding(len(QUERY_KINDS), 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
|
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
|
# direction matters: a constraint points from the part to the fixture, a
|
||||||
# conduct edge from source to sink. Two tables, not one symmetric table.
|
# 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)
|
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_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))
|
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
|
# the intervention itself: which edge or entity the question removes
|
||||||
if edit_op is not None and edit_idx is not None:
|
if edit_op is not None and edit_idx is not None:
|
||||||
|
|||||||
Reference in new issue
Block a user