angle_emb.lossο
Functionsο
|
Compute categorical crossentropy |
|
Compute cosine loss |
|
Compute angle loss |
|
Compute in-batch negative loss, i.e., contrastive loss |
|
Compute contrastive with negative loss |
Module Contentsο
- angle_emb.loss.categorical_crossentropy_loss(y_true: torch.Tensor, y_pred: torch.Tensor, from_logits: bool = True) torch.Tensor[source]ο
Compute categorical crossentropy
- Parameters:
y_true β torch.Tensor, ground truth
y_pred β torch.Tensor, model output
from_logits β bool, True means y_pred has not transformed by softmax, default True
- Returns:
torch.Tensor, loss value
- angle_emb.loss.cosine_loss(y_true: torch.Tensor, y_pred: torch.Tensor, tau: float = 20.0) torch.Tensor[source]ο
Compute cosine loss
- Parameters:
y_true β torch.Tensor, ground truth. The y_true must be zigzag style, such as [x[0][0], x[0][1], x[1][0], x[1][1], β¦], where (x[0][0], x[0][1]) stands for a pair.
y_pred β torch.Tensor, model output. The y_pred must be zigzag style, such as [o[0][0], o[0][1], o[1][0], o[1][1], β¦], where (o[0][0], o[0][1]) stands for a pair.
tau β float, scale factor, default 20
- Returns:
torch.Tensor, loss value
- angle_emb.loss.angle_loss(y_true: torch.Tensor, y_pred: torch.Tensor, tau: float = 1.0, pooling_strategy: str = 'sum')[source]ο
Compute angle loss
- Parameters:
y_true β torch.Tensor, ground truth. The y_true must be zigzag style, such as [x[0][0], x[0][1], x[1][0], x[1][1], β¦], where (x[0][0], x[0][1]) stands for a pair.
y_pred β torch.Tensor, model output. The y_pred must be zigzag style, such as [o[0][0], o[0][1], o[1][0], o[1][1], β¦], where (o[0][0], o[0][1]) stands for a pair.
tau β float, scale factor, default 1.0
- Returns:
torch.Tensor, loss value
- angle_emb.loss.in_batch_negative_loss(y_true: torch.Tensor, y_pred: torch.Tensor, tau: float = 20.0, negative_weights: float = 0.0) torch.Tensor[source]ο
Compute in-batch negative loss, i.e., contrastive loss
- Parameters:
y_true β torch.Tensor, ground truth. The y_true must be zigzag style, such as [x[0][0], x[0][1], x[1][0], x[1][1], β¦], where (x[0][0], x[0][1]) stands for a pair.
y_pred β torch.Tensor, model output. The y_pred must be zigzag style, such as [o[0][0], o[0][1], o[1][0], o[1][1], β¦], where (o[0][0], o[0][1]) stands for a pair.
tau β float, scale factor, default 20.0
negative_weights β float, negative weights, default 0.0
- Returns:
torch.Tensor, loss value
- angle_emb.loss.contrastive_with_negative_loss(text: torch.Tensor, pos: torch.Tensor, neg: torch.Tensor | None = None, tau: float = 20.0) torch.Tensor[source]ο
Compute contrastive with negative loss
- Parameters:
text β torch.Tensor, text.
pos β torch.Tensor, positive samples of text.
neg β torch.Tensor, negative samples of text.
tau β float, scale factor, default 20.0
- Returns:
torch.Tensor, loss value