Skip to contents

Restricting the relation matrix to its diagonal drops the parameter count from d^2 to d and makes the score a three-way inner product. The cost is the symmetry it cannot escape: score(h, r, t) = score(t, r, h) always, so an antisymmetric relation is unrepresentable. That is what ComplEx was written to fix.

Usage

DistM(triples, dim, E = NULL, R = NULL, seed = 1)

Arguments

triples

Rows [head, relation, tail], zero-based.

dim

Embedding dimension.

E

Entity embeddings, optional.

R

Relation embeddings, optional.

seed

Seed for the shared generator.

Value

List with estimate, scores, symmetric_gap, m, dim.

Details

Formula: score = <h, r, t> = sum_k h_k r_k t_k.

References

Yang, Yih, He, Gao & Deng (2015). ICLR 2015, equation (3).

Examples

triples <- matrix(c(1L, 1L, 2L, 2L, 1L, 3L, 3L, 2L, 1L), ncol = 3, byrow = TRUE)
DistM(triples, dim = 4)
#> $estimate
#> [1] -0.2214821
#> 
#> $scores
#> [1]  0.6530551 -0.4343638 -0.8831374
#> 
#> $symmetric_gap
#> [1] 1.110223e-16
#> 
#> $m
#> [1] 3
#> 
#> $dim
#> [1] 4
#> 
#> $method
#> [1] "DistMult triple score"
#> 
#> attr(,"class")
#> [1] "morie_rich_result" "list"