diff --git a/spatial/model.py b/spatial/model.py index bdc3c25..159123b 100644 --- a/spatial/model.py +++ b/spatial/model.py @@ -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.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.unk_tok = nn.Parameter(torch.zeros(d)) self.query_emb = nn.Embedding(len(QUERY_KINDS), d) @@ -318,7 +324,7 @@ class RelationBackbone(nn.Module): if edge_removed is not None: live = live & ~(edge_removed > 0) 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 q = self.query_emb(q_kind).unsqueeze(1).expand(B, 1, self.d).clone()