(heads, relations, tails, margin=12)
| 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): |
nothing calls this directly
no outgoing calls
no test coverage detected