评价此页

Softmin#

class torch.nn.Softmin(dim=None)[source]#

将 Softmin 函数应用于 n 维输入张量。

对它们进行重新缩放,使 n 维输出张量的元素位于 [0, 1] 范围内并求和为 1。

Softmin 定义为

Softmin(xi)=exp(xi)jexp(xj)\text{Softmin}(x_{i}) = \frac{\exp(-x_i)}{\sum_j \exp(-x_j)} jexp(xj)exp(xi)
形状
  • Input: ()(*),其中 * 表示任意数量的附加维度

  • Output: ()(*),形状与输入相同

参数

dim (int) – Softmin 将计算的维度(因此沿 dim 的每个切片将求和为 1)。

返回

一个与输入维度和形状相同的张量,其值范围为 [0, 1]

返回类型

示例

>>> m = nn.Softmin(dim=1)
>>> input = torch.randn(2, 3)
>>> output = m(input)