matchzoo.losses
¶
Package Contents¶
Classes¶
Creates a criterion that measures rank cross entropy loss. |
|
Creates a criterion that measures rank hinge loss. |
-
class
matchzoo.losses.
RankCrossEntropyLoss
(num_neg: int = 1)¶ Bases:
torch.nn.Module
Creates a criterion that measures rank cross entropy loss.
-
__constants__
= ['num_neg']¶
-
forward
(self, y_pred: torch.Tensor, y_true: torch.Tensor)¶ Calculate rank cross entropy loss.
- Parameters
y_pred – Predicted result.
y_true – Label.
- Returns
Rank cross loss.
-
property
num_neg
(self)¶ num_neg getter.
-
-
class
matchzoo.losses.
RankHingeLoss
(num_neg: int = 1, margin: float = 1.0, reduction: str = 'mean')¶ Bases:
torch.nn.Module
Creates a criterion that measures rank hinge loss.
Given inputs \(x1\), \(x2\), two 1D mini-batch Tensors, and a label 1D mini-batch tensor \(y\) (containing 1 or -1).
If \(y = 1\) then it assumed the first input should be ranked higher (have a larger value) than the second input, and vice-versa for \(y = -1\).
The loss function for each sample in the mini-batch is:
\[loss_{x, y} = max(0, -y * (x1 - x2) + margin)\]-
__constants__
= ['num_neg', 'margin', 'reduction']¶
-
forward
(self, y_pred: torch.Tensor, y_true: torch.Tensor)¶ Calculate rank hinge loss.
- Parameters
y_pred – Predicted result.
y_true – Label.
- Returns
Hinge loss computed by user-defined margin.
-
property
num_neg
(self)¶ num_neg getter.
-
property
margin
(self)¶ margin getter.
-