dgs.models.metric.metric.NegativeSoftmaxEuclideanSquaredDistance

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

Class to compute the Softmax distribution of the negative squared 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 squared Euclidean distance between the two inputs. The second dimension of the inputs 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.