Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💃 🔱 Add HAKE Interaction #442

Draft
wants to merge 45 commits into
base: master
Choose a base branch
from
Draft

💃 🔱 Add HAKE Interaction #442

wants to merge 45 commits into from

Conversation

mberr
Copy link
Member

@mberr mberr commented May 12, 2021

This PR adds the HAKE and ModE interaction functions and modules to PyKEEN.

Learning Hierarchy-Aware Knowledge Graph Embeddings for Link Prediction.
Zhanqiu Zhang, Jianyu Cai, Yongdong Zhang, Jie Wang.
AAAI 2020

Paper @ AAAI / Preprint @ Arxiv / Official Implementation (PyTorch)

It closes #11, or at least the interaction function component of it. It does not provide the exact experimental configuration to reproduce their results.

This PR also adds the pRotatE (from Sun et al. 2019) interaction function and module, since HAKE is based on it.

# remove batch/num dimension
h_phase, h_modulus, r_phase, r_modulus, r_bias, t_phase, t_modulus = strip_dim(
h_phase, h_modulus, r_phase, r_modulus, r_bias, t_phase, t_modulus)
r_bias = r_bias.clamp(max=1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copy-paste from the interaction function. Is there a better way to do this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there isn't a more clever way to test the scoring works properly without re-writing the interaction function itself, this test isn't super useful anyway :/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It checks against broadcasting issues (although this could also be done directly on the functional form).

Copy link
Member Author

@mberr mberr May 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it only looks at the case of a tensor of shape (1,1,1,1,*d) vs. (*d) 🤔

@mberr mberr changed the title 💃 🔱 Add HAKE 💃 🔱 Add HAKE Interaction May 12, 2021
src/pykeen/nn/functional.py Outdated Show resolved Hide resolved
src/pykeen/nn/functional.py Outdated Show resolved Hide resolved

The score function is given as

.. math ::
\|\sin ((h + r - t)/2)\|_p
"""
return negative_norm((0.5 * (h + r - t)).sin(), **kwargs)
return negative_norm((0.5 * (h + r - t)).sin(), p=p, power_norm=power_norm)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cthoyt I did not yet verify that this is indeed the variant from Sun, but rather took this from the HAKE paper, where the authors claim this is the pRotate variant from Sun.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/DeepGraphLearning/KnowledgeGraphEmbedding/blob/2e440e0f9c687314d5ff67ead68ce985dc446e3a/codes/model.py#L230-L248

score = norm(sin(h + r - t)) * modulus, where modulus is a global parameter. So it is not exactly the same as the Sun variant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then let's provide both possible implementations. The trick will be to pick names that are not confusing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your version can be BRotatE ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So can we parametrize the 0.5 and also an outer multipler then have a single general interaction?

@cthoyt cthoyt added the 💃 Model Related to interaction models or interaction functions label May 16, 2021
@cthoyt cthoyt added this to the PyKEEN v1.5.0 milestone May 16, 2021
CHANGELOG.rst Outdated Show resolved Hide resolved
.. math ::
\|h \odot r - t\|

# TODO: this is like a real RotatE.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

@cthoyt cthoyt modified the milestones: PyKEEN v1.5.0, PyKEEN v1.6.0 Jun 13, 2021
@cthoyt
Copy link
Member

cthoyt commented Nov 11, 2021

@ralphabb would you be interested in giving this PR a review?

@ralphabb
Copy link
Contributor

@ralphabb would you be interested in giving this PR a review?

Sorry, I can't :(. I have a backlog to clear and some deadlines coming up.

@cthoyt
Copy link
Member

cthoyt commented Nov 12, 2021

@ralphabb would you be interested in giving this PR a review?

Sorry, I can't :(. I have a backlog to clear and some deadlines coming up.

No problem, deadlines are the student's best defense against doing stuff they don't want to! It would be great to plan a video call sometime, if you'd like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💃 Model Related to interaction models or interaction functions 💎 New Component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants