dicee.models.pykeen_models
Classes
A class for using knowledge graph embedding models implemented in Pykeen |
Module Contents
- class dicee.models.pykeen_models.PykeenKGE(args: dict)[source]
Bases:
dicee.models.base_model.BaseKGE
A class for using knowledge graph embedding models implemented in Pykeen
Notes: Pykeen_DistMult: C Pykeen_ComplEx: Pykeen_QuatE: Pykeen_MuRE: Pykeen_CP: Pykeen_HolE: Pykeen_HolE:
- model_kwargs
- name
- model
- loss_history = []
- args
- entity_embeddings = None
- relation_embeddings = None
- forward_k_vs_all(x: torch.LongTensor)[source]
# => Explicit version by this we can apply bn and dropout
# (1) Retrieve embeddings of heads and relations + apply Dropout & Normalization if given. h, r = self.get_head_relation_representation(x) # (2) Reshape (1). if self.last_dim > 0:
h = h.reshape(len(x), self.embedding_dim, self.last_dim) r = r.reshape(len(x), self.embedding_dim, self.last_dim)
# (3) Reshape all entities. if self.last_dim > 0:
t = self.entity_embeddings.weight.reshape(self.num_entities, self.embedding_dim, self.last_dim)
- else:
t = self.entity_embeddings.weight
# (4) Call the score_t from interactions to generate triple scores. return self.interaction.score_t(h=h, r=r, all_entities=t, slice_size=1)
- forward_triples(x: torch.LongTensor) torch.FloatTensor [source]
# => Explicit version by this we can apply bn and dropout
# (1) Retrieve embeddings of heads, relations and tails and apply Dropout & Normalization if given. h, r, t = self.get_triple_representation(x) # (2) Reshape (1). if self.last_dim > 0:
h = h.reshape(len(x), self.embedding_dim, self.last_dim) r = r.reshape(len(x), self.embedding_dim, self.last_dim) t = t.reshape(len(x), self.embedding_dim, self.last_dim)
# (3) Compute the triple score return self.interaction.score(h=h, r=r, t=t, slice_size=None, slice_dim=0)