fn

softmin

Tensor
softmin(x: Tensor, dim: int | None = None)
source

Softmin — softmax applied to the negation of the input.

Useful when small input values should receive high probability, e.g. when x represents distances or costs and a soft-argmin is needed.

Parameters

xTensor
Input tensor of any shape.
dimint= None
Dimension along which softmin is computed. Defaults to the last dimension (-1).

Returns

Tensor

Tensor of the same shape with values summing to 1 along dim.

Notes

softmin(x)i=softmax(x)i=exijexj\text{softmin}(x)_i = \text{softmax}(-x)_i = \frac{e^{-x_i}}{\sum_j e^{-x_j}}

Exactly equivalent to softmax on the negated input; produced as a separate function purely for readability when modelling minimum-cost attention or temperature-scaled retrieval.

Examples

>>> import lucid
>>> from lucid.nn.functional import softmin
>>> x = lucid.tensor([[1.0, 2.0, 3.0]])
>>> softmin(x, dim=1)
Tensor([[0.6652, 0.2447, 0.0900]])