dicee.abstracts
Classes
Abstract class for Trainer class for knowledge graph embedding models |
|
Abstract/base class for using knowledge graph embedding models interactively. |
|
Abstract class for Callback class for knowledge graph embedding models |
|
Abstract class for Callback class for knowledge graph embedding models |
|
Abstract/base class for training knowledge graph embedding models interactively. |
Module Contents
- class dicee.abstracts.AbstractTrainer(args, callbacks)[source]
Abstract class for Trainer class for knowledge graph embedding models
Parameter
- argsstr
?
- callbacks: list
?
- attributes
- callbacks
- is_global_zero = True
- global_rank = 0
- local_rank = 0
- strategy = None
- on_fit_start(*args, **kwargs)[source]
A function to call callbacks before the training starts.
Parameter
args
kwargs
- rtype:
None
- on_fit_end(*args, **kwargs)[source]
A function to call callbacks at the ned of the training.
Parameter
args
kwargs
- rtype:
None
- on_train_epoch_end(*args, **kwargs)[source]
A function to call callbacks at the end of an epoch.
Parameter
args
kwargs
- rtype:
None
- class dicee.abstracts.BaseInteractiveKGE(path: str = None, url: str = None, construct_ensemble: bool = False, model_name: str = None, apply_semantic_constraint: bool = False)[source]
Abstract/base class for using knowledge graph embedding models interactively.
Parameter
- path_of_pretrained_model_dirstr
?
- construct_ensemble: boolean
?
model_name: str apply_semantic_constraint : boolean
- construct_ensemble = False
- apply_semantic_constraint = False
- configs
- get_bpe_token_representation(str_entity_or_relation: List[str] | str) List[List[int]] | List[int] [source]
- Parameters:
str_entity_or_relation (corresponds to a str or a list of strings to be tokenized via BPE and shaped.)
- Return type:
A list integer(s) or a list of lists containing integer(s)
- get_padded_bpe_triple_representation(triples: List[List[str]]) Tuple[List, List, List] [source]
- Parameters:
triples
- property name
- index_triple(head_entity: List[str], relation: List[str], tail_entity: List[str]) Tuple[torch.LongTensor, torch.LongTensor, torch.LongTensor] [source]
Index Triple
Parameter
head_entity: List[str]
String representation of selected entities.
relation: List[str]
String representation of selected relations.
tail_entity: List[str]
String representation of selected entities.
Returns: Tuple
pytorch tensor of triple score
- get_entity_embeddings(items: List[str])[source]
Return embedding of an entity given its string representation
Parameter
- items:
entities
- get_relation_embeddings(items: List[str])[source]
Return embedding of a relation given its string representation
Parameter
- items:
relations
- class dicee.abstracts.InteractiveQueryDecomposition[source]
- class dicee.abstracts.AbstractCallback[source]
Bases:
abc.ABC
,lightning.pytorch.callbacks.Callback
Abstract class for Callback class for knowledge graph embedding models
Parameter
- on_init_end(*args, **kwargs)[source]
Call at the beginning of the training.
Parameter
trainer:
model:
- rtype:
None
- on_fit_start(trainer, model)[source]
Call at the beginning of the training.
Parameter
trainer:
model:
- rtype:
None
- on_train_epoch_end(trainer, model)[source]
Call at the end of each epoch during training.
Parameter
trainer:
model:
- rtype:
None
- class dicee.abstracts.AbstractPPECallback(num_epochs, path, epoch_to_start, last_percent_to_consider)[source]
Bases:
AbstractCallback
Abstract class for Callback class for knowledge graph embedding models
Parameter
- num_epochs
- path
- sample_counter = 0
- epoch_count = 0
- alphas = None
- on_fit_start(trainer, model)[source]
Call at the beginning of the training.
Parameter
trainer:
model:
- rtype:
None
- class dicee.abstracts.BaseInteractiveTrainKGE[source]
Abstract/base class for training knowledge graph embedding models interactively. This class provides methods for re-training KGE models and also Literal Embedding model.
- train_triples(h: List[str], r: List[str], t: List[str], labels: List[float], iteration=2, optimizer=None)[source]
- train_k_vs_all(h, r, iteration=1, lr=0.001)[source]
Train k vs all :param head_entity: :param relation: :param iteration: :param lr: :return:
- train(kg, lr=0.1, epoch=10, batch_size=32, neg_sample_ratio=10, num_workers=1) None [source]
Retrained a pretrain model on an input KG via negative sampling.
- train_literals(train_file_path: str = None, num_epochs: int = 100, lit_lr: float = 0.001, lit_normalization_type: str = 'z-norm', batch_size: int = 1024, sampling_ratio: float = None, random_seed=1, loader_backend: str = 'pandas', freeze_entity_embeddings: bool = True, gate_residual: bool = True, device: str = None)[source]
Trains the Literal Embeddings model using literal data.
- Parameters:
train_file_path (str) – Path to the training data file.
num_epochs (int) – Number of training epochs.
lit_lr (float) – Learning rate for the literal model.
norm_type (str) – Normalization type to use (‘z-norm’, ‘min-max’, or None).
batch_size (int) – Batch size for training.
sampling_ratio (float) – Ratio of training triples to use.
loader_backend (str) – Backend for loading the dataset (‘pandas’ or ‘rdflib’).
freeze_entity_embeddings (bool) – If True, freeze the entity embeddings during training.
gate_residual (bool) – If True, use gate residual connections in the model.
device (str) – Device to use for training (‘cuda’ or ‘cpu’). If None, will use available GPU or CPU.