newsreclib.models.components package

Subpackages

Submodules

newsreclib.models.components.losses module

class newsreclib.models.components.losses.SupConLoss(temperature=0.1, **kwargs)[source]

Bases: SupConLoss

compute_loss(embeddings, labels, indices_tuple, ref_emb, ref_labels)[source]

This has to be implemented and is what actually computes the loss.

training: bool

newsreclib.models.components.utils module

newsreclib.models.components.utils.pairwise_cosine_similarity(x: Tensor, y: Tensor, zero_diagonal: bool = False) Tensor[source]

Implemented from https://github.com/duynguyen-0203/miner/blob/master/src/utils.py

Calculates the pairwise cosine similarity matrix.

Parameters:
  • x – (batch_size, M, d)

  • y – (batch_size, N, d)

  • zero_diagonal – Determines if the diagonal of the distance matrix should be set to zero.

Returns:

A single-value tensor with the pairwise cosine similarity between x and y.

Module contents