dgs.models.metric.metric.NegativeSoftmaxEuclideanDistance

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

Class to compute the Softmax distribution of the negative Euclidean distance.

Keyword Arguments:

softmax_dim (int) – The dimension along which to compute the softmax.

Methods

__init__(*args, softmax_dim: int = -1, **kwargs)[source]
forward(input1: torch.Tensor, input2: torch.Tensor) torch.Tensor[source]

First compute the Euclidean distance between the two inputs, of which the second dimension has to match. Then compute the softmax of the negative distance along the second dimension.

Parameters:
  • input1 – tensor of shape [a x E]

  • input2 – tensor of shape [b x E]

Returns:

A tensor of shape [a x b] containing the similarity between the inputs as probability. By default, the softmax is computed along the last dimension, but you can change the behavior by changing the kwargs during initialization.