dgs.models.metric.metric.CosineDistanceMetric

class dgs.models.metric.metric.CosineDistanceMetric(*args: Any, **kwargs: Any)[source]

Class to compute the cosine distance between two matrices.

Notes

The cosine distance is the complement of the cosine similarity in positive space:

\[ \begin{align}\begin{aligned}\text{cosine similarity} = S_C(A,B) = \frac{\mathbf{A} \cdot \mathbf{B}}{\|\mathbf{A}\| \|\mathbf{B}\|}\\\text{cosine distance} = 1 - S_C(A,B)\end{aligned}\end{align} \]

Methods

__init__(*args, **kwargs) None[source]
forward(input1: torch.Tensor, input2: torch.Tensor) torch.Tensor[source]
Parameters:
  • input1 – tensor of shape [a x E]

  • input2 – tensor of shape [b x E]

Returns:

tensor of shape [a x b] containing the distances.