ttrouill / complex

Source code for experiments in the papers "Complex Embeddings for Simple Link Prediction" (ICML 2016) and "Knowledge Graph Completion via Complex Tensor Factorization" (JMLR 2017).
Other
319 stars 83 forks source link

About Hermitian product #18

Closed EJHyun closed 2 years ago

EJHyun commented 2 years ago

Dear author Hi im student from South Korea I have a question about hermitian product which is used in ComplEx's score function. I would be glad if you explain how the equation (11) was made..

In detail, lets assume we have entity A's embedding vector of dimension 100. (Tensor shape (1, 100)) To treat this embedding vector as a complex vector, ComplEx divides this 100-dimension embedding into 2 pieces, Re and Im. (Real, Imaginary each would have 50-dimension in this case)

Let's assume we have another entity B's embedding too. Then the similarity(= inner product) of these two entities can be computed with hermitian product. (Let's say <> is a sum of element-wise multiplication>

Similarity(A,B) = <Re(A) , Re(B)> + <-Im(A) , Im(B)>

This is what I understood(Am I right?) and here is the question. ComplEx's score function calculates score with 3 vectors (2 entities and 1 relation)... How can I do this?? I mean, How did you made equation (11)??

Uhh..lets say relation between A, B is R. The paper says we can calculate 3 vector's hermitian product just like the equation (11) does.

<Re(R), Re(A), Re(B)> + <Re(R), Im(A), Im(B)> + <Im(R), Re(A), Im(B)> - <Im(R), Im(A), Re(B)>

How did you made this equation??

I'll be really glad if you tell me how.. Thank you!

ttrouill commented 2 years ago

Hi !

So as mentionned in the foot note 2 in page 4 of the ICML paper, there is no "proper" extension of the Hermitian product to three dimension, we simply extended it as the sum of the element wise products of three vectors instead of two. It's nothing more than the distribution of the products:

<R,A,B> = <Re(R) + i Im(R), Re(A) + i Im(A), Re(B) + i Im(B) > = SUM_j ( ( Re(r_j) + i Im(r_j) ) ( Re(a_j) + i Im(a_j) ) ( Re(b_j) + i Im(b_j) ) ) = SUM_j ( ( Re(r_j) Re(a_j) Re(b_j) ) + ( Re(r_j) Im(a_j) Im (b_j) ) + ( Im(r_j) Re(a_j) Im(b_j) ) - ( Im(r_j) Im(a_j) Re(b_j) ) ) = <Re(R), Re(A), Re(B)> + <Re(R), Im(A), Im(B)> + <Im(R), Re(A), Im(B)> - <Im(R), Im(A), Re(B)>

Write it down it'll be clearer, hope it helps ! Also, a 100-dimension complex embedding has a 100-dimension real part and a 100-dimension imaginary part, not 50 !

EJHyun commented 2 years ago

Thank you so much! Your answer was truly helpful

Thanks!!