dicee.abstracts

Classes

AbstractTrainer

Abstract class for Trainer class for knowledge graph embedding models

BaseInteractiveKGE

Abstract/base class for using knowledge graph embedding models interactively.

AbstractCallback

Abstract class for Callback class for knowledge graph embedding models

AbstractPPECallback

Abstract class for Callback class for knowledge graph embedding models

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
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

on_train_batch_end(*args, **kwargs)[source]

A function to call callbacks at the end of each mini-batch during training.

Parameter

args

kwargs

rtype:

None

static save_checkpoint(full_path: str, model) None[source]

A static function to save a model into disk

Parameter

full_path : str

model:

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
apply_semantic_constraint
configs
get_eval_report() dict[source]
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

set_model_train_mode() None[source]

Setting the model into training mode

Parameter

set_model_eval_mode() None[source]

Setting the model into eval mode

Parameter

property name
sample_entity(n: int) List[str][source]
sample_relation(n: int) List[str][source]
is_seen(entity: str = None, relation: str = None) bool[source]
save() None[source]
get_entity_index(x: str)[source]
get_relation_index(x: str)[source]
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

add_new_entity_embeddings(entity_name: str = None, embeddings: torch.FloatTensor = None)[source]
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

construct_input_and_output(head_entity: List[str], relation: List[str], tail_entity: List[str], labels)[source]

Construct a data point :param head_entity: :param relation: :param tail_entity: :param labels: :return:

parameters()[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_start(*args, **kwargs)[source]

Parameter

trainer:

model:

rtype:

None

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

on_train_batch_end(*args, **kwargs)[source]

Call at the end of each mini-batch during the training.

Parameter

trainer:

model:

rtype:

None

on_fit_end(*args, **kwargs)[source]

Call at the end of the 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

on_fit_end(trainer, model)[source]

Call at the end of the training.

Parameter

trainer:

model:

rtype:

None

store_ensemble(param_ensemble) None[source]