MCPcopy Create free account
hub / github.com/DeepGraphLearning/graphvite / RotatE

Method RotatE

python/graphvite/application/network.py:84–96  ·  view source on GitHub ↗
(heads, relations, tails, margin=12)

Source from the content-addressed store, hash-verified

82
83 @staticmethod
84 def RotatE(heads, relations, tails, margin=12):
85 dim = heads.size(1) // 2
86
87 head_re, head_im = heads.view(-1, dim, 2).permute(2, 0, 1)
88 tail_re, tail_im = tails.view(-1, dim, 2).permute(2, 0, 1)
89 relations = relations[:, :dim]
90 relation_re, relation_im = torch.cos(relations), torch.sin(relations)
91
92 x_re = head_re * relation_re - head_im * relation_im - tail_re
93 x_im = head_re * relation_im + head_im * relation_re - tail_im
94 x = torch.stack([x_re, x_im], dim=0)
95 score = margin - x.norm(p=2, dim=0).sum(dim=1)
96 return score
97
98 @staticmethod
99 def DistMult(heads, relations, tails):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected