loss
Adv_Loss
- class unKR.loss.Adv_Loss.Adv_Loss(args, model)[source]
Bases:
Module
Negative sampling loss with self-adversarial training.
- args
Some pre-set parameters, such as self-adversarial temperature, etc.
- model
The KG model for training.
- forward(pos_score, neg_score, subsampling_weight=None)[source]
Negative sampling loss with self-adversarial training. In math:
L=-log sigmaleft(gamma-d_{r}(mathbf{h}, mathbf{t})
ight)-sum_{i=1}^{n} pleft(h_{i}^{prime}, r, t_{i}^{prime} ight) log sigmaleft(d_{r}left(mathbf{h}_{i}^{prime}, mathbf{t}_{i}^{prime} ight)-gamma ight)
- Args:
pos_score: The score of positive samples. neg_score: The score of negative samples. subsampling_weight: The weight for correcting pos_score and neg_score.
- Returns:
loss: The training loss for back propagation.
BEUrRE_Loss
- class unKR.loss.BEUrRE_Loss.BEUrRE_Loss(args, model)[source]
Bases:
Module
The loss function of BEUrRE
- args
Some pre-set parameters, etc
- model
The BEUrRE model for training.
- L2_regularization(model, ids, args)[source]
Computes the L2 regularization loss for the model.
- Parameters:
model – The BEUrRE model instance.
ids – Tensor of triple ids.
args – Model configuration parameters including regularization coefficients.
- Returns:
The L2 regularization loss.
- Return type:
L2_reg
- forward(model, ids, negative_samples, args)[source]
Calculating the total loss including MSE loss, logic loss, and L2 regularization.
- Parameters:
model – The BEUrRE model instance.
ids – Tensor of positive triple ids.
negative_samples – Tensor of negative triple ids.
args – Model configuration parameters including regularization coefficients.
- Returns:
The total loss combining MSE loss, logic loss, and L2 regularization.
- Return type:
loss
- get_logic_loss(model, ids, args)[source]
Calculates the logic loss for the model based on transitive and composite rule regularizations.
- Parameters:
model – The BEUrRE model instance.
ids – Tensor of triple ids.
args – Model configuration parameters including regularization coefficients.
- Returns:
The logic loss calculated from transitive and composite rule regularizations.
FocusE_Loss
- class unKR.loss.FocusE_Loss.FocusE_Loss(args, model)[source]
Bases:
Module
The loss function of FocusE
- args
Some pre-set parameters, etc
- model
The FocusE model for training.
- forward(pos_score, neg_score, pos_sample)[source]
Calculating the loss, which includes the negative log-likelihood loss and L3 regularization.
- Parameters:
pos_score – Tensor of scores for positive samples.
neg_score – Tensor of scores for negative samples.
pos_sample – Tensor of positive samples.
- Returns:
The total loss of FocusE.
GMUC_Loss
- class unKR.loss.GMUC_Loss.GMUC_Loss(args, model)[source]
Bases:
Module
GMUC Loss
- args
Some pre-set parameters, etc
- model
The UKG model for training.
- forward(query_scores, query_scores_var, query_ae_loss, false_scores, query_confidence)[source]
- Parameters:
query_scores – The matching scores for link prediction.
query_scores_var – The prediction value of confidence.
query_ae_loss – The loss in the matching process,
false_scores – The loss for false set.
query_confidence – The true value for confidence in query set.
- Returns:
The training loss for back propagation.
- Return type:
loss
GMUCp_Loss
- class unKR.loss.GMUCp_Loss.GMUCp_Loss(args, model)[source]
Bases:
Module
GMUC+ Loss
- args
Some pre-set parameters, etc
- model
The UKG model for training.
- forward(query_scores, query_scores_var, false_scores, query_confidence, symbolid_ic)[source]
- Parameters:
query_scores – The matching scores for link prediction.
query_scores_var – The prediction value of confidence.
false_scores – The loss for false set.
query_confidence – The true value for confidence in query set.
symbolid_ic – The loss for symbolid-ic value.
- Returns:
The training loss for back propagation.
- Return type:
loss
GTransE_Loss
- class unKR.loss.GTransE_Loss.GTransE_Loss(args, model)[source]
Bases:
Module
- forward(pos_score, neg_score, pos_sample)[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
PASSLEAF_Loss
- class unKR.loss.PASSLEAF_Loss.PASSLEAF_Loss(args, model)[source]
Bases:
Module
- forward(pos_score, neg_score, pos_sample, semi_score=None, semi_sample=None)[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
UKGE_Loss
- class unKR.loss.UKGE_Loss.UKGE_Loss(args, model)[source]
Bases:
Module
- forward(pos_score, neg_score, pos_sample)[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
UKGE_PSL_Loss
- class unKR.loss.UKGE_PSL_Loss.UKGE_PSL_Loss(args, model)[source]
Bases:
Module
Loss of UKGE with PSL
- forward(pos_score, neg_score, PSL_score, pos_sample, neg_sample, PSL_sample)[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
UKGsE_Loss
- class unKR.loss.UKGsE_Loss.UKGsE_Loss(args, model)[source]
Bases:
Module
- forward(pos_score, neg_score, pos_sample)[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
UPGAT_Loss
- class unKR.loss.UPGAT_Loss.UPGAT_Loss(args, model)[source]
Bases:
Module
- forward(pos_score, neg_score, pos_sample, pseudo_score=None, pseudo_sample=None)[source]
Calculating the loss score of UPGAT model.
- Parameters:
pos_score – The score of positive samples.
neg_score – The score of negative samples.
pos_sample – The positive samples.
pseudo_score – The score of pseudo samples, defaults to None.
pseudo_sample – The pseudo samples, defaults to None.
- Returns:
The training loss for back propagation.
- Return type:
loss