uma-pi1 / kge

LibKGE - A knowledge graph embedding library for reproducible research
MIT License
765 stars 124 forks source link

N3 implementation for ComplEx and Reciprocal ComplEx #265

Closed Kenkoko closed 1 year ago

Kenkoko commented 2 years ago

Hi @rgemulla @rufex2001,

This is the implementation of N3 - Chen et al. (2021).

Let $u$ be an embedding vector. The formula for L3 is: $$|u |^3p = \sum{j=1}^{n_d}|u_j|^3$$

The main difference between N3 and L3 implementation is that Chen et al. (2021) considered an embedding vector $u$ as a complex vector while LibKGE considered an embedding vector as a real vector $u$.

If $u$ is a complex vector, $u_j = u'_j + iu''_j$ where $u'_j$ is the real part and $u''_j$ is the imaginary. The L3 would be:

$$|u |^3p = \sum{j=1}^{n_d}|uj|^3 = \sum{j=1}^{n_d}\left(\sqrt{{u'}_j^2 + {u''}_j^2}\right)^3$$

If $u$ is a real vector, the L3 would be:

$$|u |^3p = \sum{j=1}^{n_d}|u_j|^3 $$

where $|u_j|$ is absolute value of $u_j$.

This pull request included a new function that calculates the complex vectors' norm before cubing. The calculation is only conducted for the ComplEx and Reciprocal ComplEx models.

Please let me know what you think about the code. If you have any suggestions, please feel free to suggest.

Kenkoko commented 2 years ago

Hi @rgemulla,

I have made some changes; please let me know what you think about those changes.

Kenkoko commented 2 years ago

Hi @rgemulla,

I have made some changes based on your comments; please let me know what you think.

rgemulla commented 2 years ago

Looks great!

@rufex2001 If ok with you as well, please update CHANGELOG and merge.

Kenkoko commented 2 years ago

Hi @rgemulla, @rufex2001,

If you're all okay with my pull-request, please, let me reproduce the results from Chen et al. (2021) first before merging to make sure that everything works as we expect.

Kenkoko commented 2 years ago

Hi @rgemulla, @rufex2001,

If you're all okay with my pull-request, please, let me reproduce the results from Chen et al. (2021) first before merging to make sure that everything works as we expect.

Hi @rgemulla, @rufex2001,

I have successfully reproduced the Chen et al. (2021), Lacroix et al. (2018) result.

2022-09-01 05:08:03.621303 [56e0d1a2]   mean_reciprocal_rank_filtered_with_test: 0.37134475468705447
2022-09-01 05:08:03.621313 [56e0d1a2]   mean_reciprocal_rank_filtered_with_test_1-1: 0.5777754184014783
2022-09-01 05:08:03.621329 [56e0d1a2]   mean_reciprocal_rank_filtered_with_test_1-N: 0.29677387943432404
2022-09-01 05:08:03.621339 [56e0d1a2]   mean_reciprocal_rank_filtered_with_test_M-1: 0.4563853876377509
2022-09-01 05:08:03.621349 [56e0d1a2]   mean_reciprocal_rank_filtered_with_test_M-N: 0.34782264950258296
2022-09-01 05:08:03.621359 [56e0d1a2]   metric_name: mean_reciprocal_rank_filtered_with_test

I would like to send you the log file for detail discussion.

kge.log

rgemulla commented 1 year ago

@Kenkoko Thanks! Can you also post the config file you used here?

@rufex2001 If you agree, please update changelog and merge.

Kenkoko commented 1 year ago

Hi @rgemulla, @rufex2001

GitHub doesn't allow me to upload a Yaml file. So I changed the config.yaml file to txt file.

Please let me know if you need anything further ^^

config.txt

rufex2001 commented 1 year ago

Looks good! @Kenkoko thanks for the contribution and the config file for reproduction!