speechbrain.utils.distances module
Distance metrics and related functions
Summary
Functions:
Computes a matrix evaluating all pairwise cosine similarities. |
Reference
- speechbrain.utils.distances.cosine_similarity_matrix(a: Tensor, b: Tensor, eps: float = 1e-08) Tensor[source]
Computes a matrix evaluating all pairwise cosine similarities. The cosine similarity can otherwise be determined with
torch.nn.CosineSimilarity.- Parameters:
a (torch.Tensor) – Tensor of shape
[..., X, dim]wheredimis the dimension where the cosine similarity will be computed andXis any value>= 0.b (torch.Tensor) – Tensor of shape
[..., Y, dim], where other dimensions are otherwise identical toa’s andYis any value>= 0.eps (float) – Epsilon value for numerical stability, in order to avoid a division by zero. Does not significantly affect results.
- Returns:
Tensor of shape
[..., X, Y]living on the same device and dtype as the input tensors. e.g. ignoring first dimensionsout[3, 0]would be the cosine similarity ofa[3]andb[0].- Return type: