You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mindspore.nn.Softmax.rst 1.3 kB

12345678910111213141516171819202122232425262728293031323334
  1. mindspore.nn.Softmax
  2. ====================
  3. .. py:class:: mindspore.nn.Softmax(axis=-1)
  4. Softmax函数,它是二分类函数 :class:`mindspore.nn.Sigmoid` 在多分类上的推广,目的是将多分类的结果以概率的形式展现出来。
  5. 对输入Tensor在轴 `axis` 上的元素计算其指数函数值,然后归一化到[0, 1]范围,总和为1。
  6. Softmax定义为:
  7. .. math::
  8. \text{softmax}(x_{i}) = \frac{\exp(x_i)}{\sum_{j=0}^{n-1}\exp(x_j)},
  9. 其中, :math:`x_{i}` 是输入Tensor在轴 `axis` 上的第 :math:`i` 个元素。
  10. **参数:**
  11. **axis** (Union[int, tuple[int]]) - 指定Softmax运算的轴axis,假设输入 `x` 的维度为x.ndim,则axis的范围为 `[-x.ndim, x.ndim)` ,-1表示最后一个维度。默认值:-1。
  12. **输入:**
  13. **x** (Tensor) - 用于计算Softmax函数的Tensor,数据类型为float16或float32。
  14. **输出:**
  15. Tensor,数据类型和shape与 `x` 相同,取值范围为[0, 1]。
  16. **异常:**
  17. - **TypeError** - `axis` 既不是int也不是tuple。
  18. - **TypeError** - `x` 的数据类型既不是float16也不是float32。
  19. - **ValueError** - `axis` 是长度小于1的tuple。
  20. - **ValueError** - `axis` 是一个tuple,其元素不都在 `[-x.ndim, x.ndim)` 范围内。