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

Method QuatE

python/graphvite/application/network.py:129–143  ·  view source on GitHub ↗
(heads, relations, tails)

Source from the content-addressed store, hash-verified

127
128 @staticmethod
129 def QuatE(heads, relations, tails):
130 dim = heads.size(1) // 4
131
132 head_r, head_i, head_j, head_k = heads.view(-1, dim, 4).permute(2, 0, 1)
133 tail_r, tail_i, tail_j, tail_k = tails.view(-1, dim, 4).permute(2, 0, 1)
134 relation_r, relation_i, relation_j, relation_k = relations.view(-1, dim, 4).permute(2, 0, 1)
135
136 relation_norm = relations.view(-1, dim, 4).norm(p=2, dim=2)
137 x_r = head_r * relation_r - head_i * relation_i - head_j * relation_j - head_k * relation_k
138 x_i = head_r * relation_i + head_i * relation_r + head_j * relation_k - head_k * relation_j
139 x_j = head_r * relation_j - head_i * relation_k + head_j * relation_r + head_k * relation_i
140 x_k = head_r * relation_k + head_i * relation_j - head_j * relation_i + head_k * relation_r
141 x = (x_r * tail_r + x_i * tail_i + x_j * tail_j + x_k * tail_k) / (relation_norm + 1e-15)
142 score = x.sum(dim=1)
143 return score

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected