newsreclib.models.components package
Subpackages
Submodules
newsreclib.models.components.losses module
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
andy
.