- class ContrastiveLoss(distance_metric_name: Distance = Distance.COSINE, margin: float = 0.5, size_average: bool = True)¶
Expects as input two texts and a label of either 0 or 1. If the label == 1, then the distance between the two embeddings is reduced. If the label == 0, then the distance between the embeddings is increased.
- Further information:
- forward(embeddings: Tensor, pairs: LongTensor, labels: Tensor, subgroups: Tensor, **kwargs) Tensor ¶
Compute loss value.
embeddings – Batch of embeddings, first half of embeddings are embeddings of first objects in pairs, second half are embeddings of second objects in pairs.
pairs – Indices of corresponding objects in pairs.
labels – Scores of positive and negative objects.
subgroups – subgroups to distinguish objects which can and cannot be used as negative examples
**kwargs – additional key-word arguments for generalization of loss call
Tensor – averaged or summed loss value
- get_config_dict() Dict[str, Any] ¶
Config used in saving and loading purposes.
Config object has to be JSON-serializable.
Dict[str, Any] – JSON-serializable dict of params
- training: bool¶