Inference
Entity Inference
- class torchkge.inference.EntityInference(model, known_entities, known_relations, top_k=1, missing='tails', dictionary=None)[source]
Use trained embedding model to infer missing entities in triples.
- Parameters
model (torchkge.models.interfaces.Model) – Embedding model inheriting from the right interface.
known_entities (torch.Tensor, shape: (n_facts), dtype: torch.long) – List of the indices of known entities.
known_relations (torch.Tensor, shape: (n_facts), dtype: torch.long) – List of the indices of known relations.
top_k (int) – Indicates the number of top predictions to return.
missing (str) – String indicating if the missing entities are the heads or the tails.
dictionary (dict, optional (default=None)) – Dictionary of possible heads or tails (depending on the value of missing). It is used to filter predictions that are known to be True in the training set in order to return only new facts.
- model
Embedding model inheriting from the right interface.
- known_entities
List of the indices of known entities.
- Type
torch.Tensor, shape: (n_facts), dtype: torch.long
- known_relations
List of the indices of known relations.
- Type
torch.Tensor, shape: (n_facts), dtype: torch.long
- top_k
Indicates the number of top predictions to return.
- Type
int
- missing
String indicating if the missing entities are the heads or the tails.
- Type
str
- dictionary
Dictionary of possible heads or tails (depending on the value of missing). It is used to filter predictions that are known to be True in the training set in order to return only new facts.
- Type
dict, optional (default=None)
- predictions
List of the indices of predicted entities for each test fact.
- Type
torch.Tensor, shape: (n_facts, self.top_k), dtype: torch.long
- scores
List of the scores of resulting triples for each test fact.
- Type
torch.Tensor, shape: (n_facts, self.top_k), dtype: torch.float
Relation Inference
- class torchkge.inference.RelationInference(model, entities1, entities2, top_k=1, dictionary=None)[source]
Use trained embedding model to infer missing relations in triples.
- Parameters
model (torchkge.models.interfaces.Model) – Embedding model inheriting from the right interface.
entities1 (torch.Tensor, shape: (n_facts), dtype: torch.long) – List of the indices of known entities 1.
entities2 (torch.Tensor, shape: (n_facts), dtype: torch.long) – List of the indices of known entities 2.
top_k (int) – Indicates the number of top predictions to return.
dictionary (dict, optional (default=None)) – Dictionary of possible relations. It is used to filter predictions that are known to be True in the training set in order to return only new facts.
- model
Embedding model inheriting from the right interface.
- entities1
List of the indices of known entities 1.
- Type
torch.Tensor, shape: (n_facts), dtype: torch.long
- entities2
List of the indices of known entities 2.
- Type
torch.Tensor, shape: (n_facts), dtype: torch.long
- top_k
Indicates the number of top predictions to return.
- Type
int
- dictionary
Dictionary of possible relations. It is used to filter predictions that are known to be True in the training set in order to return only new facts.
- Type
dict, optional (default=None)
- predictions
List of the indices of predicted relations for each test fact.
- Type
torch.Tensor, shape: (n_facts, self.top_k), dtype: torch.long
- scores
List of the scores of resulting triples for each test fact.
- Type
torch.Tensor, shape: (n_facts, self.top_k), dtype: torch.float