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 Transformer Interaction #714

Merged
merged 13 commits into from
Jan 8, 2022
Merged

Conversation

mberr
Copy link
Member

@mberr mberr commented Jan 7, 2022

This PR adds the Transformer-based interaction from the StarE paper.

cf.

Note: this PR doesn't add the citation since it's already in the references.rst because we referenced it before.

@mberr mberr changed the title Add Transformer Interaction 🚚🤖 Add Transformer Interaction Jan 7, 2022
@mberr mberr requested a review from mali-git January 7, 2022 15:02
@cthoyt
Copy link
Member

cthoyt commented Jan 7, 2022

Is the concept of the transformer interaction an idea proposed by galkin et al. (2020)? Wondering if I should add the citation in

@mberr mberr requested a review from migalkin January 7, 2022 19:28
trigger ci
@cthoyt
Copy link
Member

cthoyt commented Jan 7, 2022

Is there a blocker for adding a StarE model appropriate for regular KGs?

@mberr
Copy link
Member Author

mberr commented Jan 7, 2022

Is there a blocker for adding a StarE model appropriate for regular KGs?

StarE collapses to CompGCN if you remove all the hyper-relational parts 🙂

(StarE is "only" the encoder part of what is described in the publication; the decoder is this interaction function)

@cthoyt
Copy link
Member

cthoyt commented Jan 7, 2022

So then it's fine to finish this PR without adding a new model, but it would be important to write some narrative documentation explaining how one might use this interaction to construct a new model

@mberr
Copy link
Member Author

mberr commented Jan 7, 2022

So then it's fine to finish this PR without adding a new model, but it would be important to write some narrative documentation explaining how one might use this interaction to construct a new model

This should be the place to put it? To slightly modify the example there and create an "anonymous" model instead of declaring a new class:

from pykeen.models import ERModel
from pykeen.nn import EmbeddingSpecification
from pykeen.losses import BCEWithLogitsLoss
model = ERModel(
    triples_factory=...,
    loss=BCEWithLogitsLoss(), # TODO: we should support passing a string here, and use the loss-resolver to resolve it
    interaction="transformer",
    entity_representations=EmbeddingSpecification(embedding_dim=64),
    relation_representations=EmbeddingSpecification(embedding_dim=64),
)

@migalkin
Copy link
Member

migalkin commented Jan 8, 2022

Thanks Max!
I debugged the test case and the interaction function seems to work as expected 🚀

A few minor comments:

  • Position embedding is initialized randomly self.position_embeddings = nn.Parameter(torch.rand(2, input_dim)) while we used xavier init. It would probably not matter for just 2 elements (instead of 43 in the StarE case), the original motivation was to initialize entities, relations, and positional encodings in the same scale (range) such that there won't be sudden gradient explosions
  • Since the final operation is the dot product, sLCWA training with margin loss doesn't make a lot of sense. LCWA + BCE is ok, sLCWA would work with BCE+sigmoid or softplus. Shall we put some warning if a user creates a pipeline with this interaction and margin loss?

@mberr
Copy link
Member Author

mberr commented Jan 8, 2022

Thanks Max! I debugged the test case and the interaction function seems to work as expected 🚀

A few minor comments:

Position embedding is initialized randomly self.position_embeddings = nn.Parameter(torch.rand(2, input_dim)) while we used xavier init. It would probably not matter for just 2 elements (instead of 43 in the StarE case), the original motivation was to initialize entities, relations, and positional encodings in the same scale (range) such that there won't be sudden gradient explosions

I changed the init to xavier with 08ae09a

Since the final operation is the dot product, sLCWA training with margin loss doesn't make a lot of sense. LCWA + BCE is ok, sLCWA would work with BCE+sigmoid or softplus. Shall we put some warning if a user creates a pipeline with this interaction and margin loss?

This PR only adds the interaction function, not a full model configuration with loss etc. I see that we lose the geometric interpretation of margin loss, but is there any other reason why dot product should not work with margin? After all, margin encourages a relative ordering of scores, which could also be achieved by dot-product based interaction, if I am not mistaken.

@cthoyt
Copy link
Member

cthoyt commented Jan 8, 2022

@PyKEEN-bot test

Copy link
Member

@cthoyt cthoyt left a comment

Choose a reason for hiding this comment

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

Sorry didn't mean to approve - I still want to see some added tutorial functions like you mentioned

trigger ci
@cthoyt cthoyt merged commit b34d593 into master Jan 8, 2022
@cthoyt cthoyt deleted the transformer-interaction branch January 8, 2022 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants