besskge.loss.MarginRankingLoss
- class besskge.loss.MarginRankingLoss(margin, negative_adversarial_sampling, negative_adversarial_scale=1.0, loss_scale=1.0, activation_function='relu')[source]
The margin ranking (or pairwise hinge) loss function.
Initialize margin ranking loss function.
- Parameters:
margin (
float
) – seeMarginBasedLossFunction.__init__()
negative_adversarial_sampling (
bool
) – seeBaseLossFunction
negative_adversarial_scale (
float
) – seeBaseLossFunction
loss_scale (
float
) – seeBaseLossFunction
activation_function (
str
) – The activation function in loss computation. Default: “relu”.
- get_negative_weights(negative_score)
Construct weights of negative samples, based on their score.
- Parameters:
negative_score (
Tensor
) – : (batch_size, n_negative) Scores of negative samples.- Return type:
- Returns:
shape: (batch_size, n_negative) if
BaseLossFunction.negative_adversarial_sampling
else () Weights of negative samples.