dicee.models.octonion
Classes
Base class for all Knowledge Graph Embedding models. |
|
Base class for all Knowledge Graph Embedding models. |
|
Additive Convolutional Octonion Knowledge Graph Embeddings |
Functions
|
|
|
Module Contents
- class dicee.models.octonion.OMult(args)[source]
Bases:
dicee.models.base_model.BaseKGEBase class for all Knowledge Graph Embedding models.
Inherits the Lightning training loop from
BaseKGELightningand adds the embedding tables, normalisation / dropout layers, and the routing logic that dispatchesforward()calls to the appropriate scoring method.Sub-classes must implement at minimum:
forward_triples()— score a batch of(h, r, t)triples.forward_k_vs_all()— score a(h, r)batch against every entity.
- Parameters:
args (dict) – Flat configuration dictionary produced by
vars(argparse.Namespace). Required keys:embedding_dim,num_entities,num_relations,learning_rate(orlr),optim,scoring_technique.
- name = 'OMult'
- static octonion_normalizer(emb_rel_e0, emb_rel_e1, emb_rel_e2, emb_rel_e3, emb_rel_e4, emb_rel_e5, emb_rel_e6, emb_rel_e7)[source]
- score(head_ent_emb: torch.FloatTensor, rel_ent_emb: torch.FloatTensor, tail_ent_emb: torch.FloatTensor)[source]
- forward_k_vs_all(x)[source]
Completed. Given a head entity and a relation (h,r), we compute scores for all possible triples,i.e., [score(h,r,x)|x in Entities] => [0.0,0.1,…,0.8], shape=> (1, |Entities|) Given a batch of head entities and relations => shape (size of batch,| Entities|)
- class dicee.models.octonion.ConvO(args: dict)[source]
Bases:
dicee.models.base_model.BaseKGEBase class for all Knowledge Graph Embedding models.
Inherits the Lightning training loop from
BaseKGELightningand adds the embedding tables, normalisation / dropout layers, and the routing logic that dispatchesforward()calls to the appropriate scoring method.Sub-classes must implement at minimum:
forward_triples()— score a batch of(h, r, t)triples.forward_k_vs_all()— score a(h, r)batch against every entity.
- Parameters:
args (dict) – Flat configuration dictionary produced by
vars(argparse.Namespace). Required keys:embedding_dim,num_entities,num_relations,learning_rate(orlr),optim,scoring_technique.
- name = 'ConvO'
- conv2d
- fc_num_input
- fc1
- bn_conv2d
- norm_fc1
- feature_map_dropout
- static octonion_normalizer(emb_rel_e0, emb_rel_e1, emb_rel_e2, emb_rel_e3, emb_rel_e4, emb_rel_e5, emb_rel_e6, emb_rel_e7)[source]
- forward_triples(x: torch.Tensor) torch.Tensor[source]
Score a batch of
(head, relation, tail)index triples.- Parameters:
x (torch.LongTensor) – Shape
(batch_size, 3)integer tensor where each row is[head_idx, relation_idx, tail_idx].- Returns:
Shape
(batch_size,)triple scores.- Return type:
torch.FloatTensor
- forward_k_vs_all(x: torch.Tensor)[source]
Given a head entity and a relation (h,r), we compute scores for all entities. [score(h,r,x)|x in Entities] => [0.0,0.1,…,0.8], shape=> (1, |Entities|) Given a batch of head entities and relations => shape (size of batch,| Entities|)
- class dicee.models.octonion.AConvO(args: dict)[source]
Bases:
dicee.models.base_model.BaseKGEAdditive Convolutional Octonion Knowledge Graph Embeddings
- name = 'AConvO'
- conv2d
- fc_num_input
- fc1
- bn_conv2d
- norm_fc1
- feature_map_dropout
- static octonion_normalizer(emb_rel_e0, emb_rel_e1, emb_rel_e2, emb_rel_e3, emb_rel_e4, emb_rel_e5, emb_rel_e6, emb_rel_e7)[source]
- forward_triples(x: torch.Tensor) torch.Tensor[source]
Score a batch of
(head, relation, tail)index triples.- Parameters:
x (torch.LongTensor) – Shape
(batch_size, 3)integer tensor where each row is[head_idx, relation_idx, tail_idx].- Returns:
Shape
(batch_size,)triple scores.- Return type:
torch.FloatTensor
- forward_k_vs_all(x: torch.Tensor)[source]
Given a head entity and a relation (h,r), we compute scores for all entities. [score(h,r,x)|x in Entities] => [0.0,0.1,…,0.8], shape=> (1, |Entities|) Given a batch of head entities and relations => shape (size of batch,| Entities|)