TransE now uses score_emb_spo
@@ -10,30 +10,11 @@ class TransEScorer(RelationalScorer):
super().__init__(config, dataset)
self._norm = config.get("transe.l_norm")
- def score_emb(self, s_emb, p_emb, o_emb, combine: str):
+ def score_emb_spo(self, s_emb, p_emb, o_emb):
n = p_emb.size(0)
- emb_dim = p_emb.size(1)
- if combine == "spo":
out = torch.norm(s_emb + p_emb - o_emb,
p=self._norm,
dim=1) * -1
- elif combine == "sp*":
- s_emb = s_emb.repeat(1, o_emb.size(0)).view(-1, emb_dim)
- p_emb = p_emb.repeat(1, o_emb.size(0)).view(-1, emb_dim)
- o_emb = o_emb.repeat(n, 1)
- out = torch.norm(s_emb + p_emb - o_emb,
- p=self._norm,
- dim=1) * -1
- elif combine == "*po":
- p_emb = p_emb.repeat(1, s_emb.size(0)).view(-1, emb_dim)
- o_emb = o_emb.repeat(1, s_emb.size(0)).view(-1, emb_dim)
- s_emb = s_emb.repeat(n, 1)
- out = torch.norm(s_emb + p_emb - o_emb,
- p=self._norm,
- dim=1) * -1
- else:
- raise ValueError('cannot handle combine="{}".format(combine)')
-
return out.view(n, -1)
