feat(spatial): 边内容加一条线性通路
"六个自由度轴是否全部被锁住"是关于集合基数的陈述,而非线性投影之和不再是计数: GELU 会把各个轴混在一起,袋和就丢掉了它到底见过哪几个轴。线性旁路让和保持为精确 的计数向量,一个阈值就能读出来。
This commit is contained in:
1 parent
830bbac4f3
commit
dd906acf4b
1 file changed
+7
-1
+7
-1
@@ -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.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.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.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)
|
||||||
@@ -318,7 +324,7 @@ class RelationBackbone(nn.Module):
|
|||||||
if edge_removed is not None:
|
if edge_removed is not None:
|
||||||
live = live & ~(edge_removed > 0)
|
live = live & ~(edge_removed > 0)
|
||||||
inc = inc * live.unsqueeze(1).to(inc.dtype)
|
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
|
# 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()
|
q = self.query_emb(q_kind).unsqueeze(1).expand(B, 1, self.d).clone()
|
||||||
|
|||||||
Reference in new issue
Block a user