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.LogSoftmax.rst 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. mindspore.nn.LogSoftmax
  2. =============================
  3. .. py:class:: mindspore.nn.LogSoftmax(axis=-1)
  4. Log Softmax激活函数。
  5. 按元素计算Log Softmax激活函数。
  6. 输入经Softmax函数、Log函数转换后,值的范围在[-inf,0)。
  7. Log Softmax定义如下:
  8. .. math::
  9. \text{logsoftmax}(x_i) = \log \left(\frac{\exp(x_i)}{\sum_{j=0}^{n-1} \exp(x_j)}\right),
  10. 其中,:math:`x_i` 是输入Tensor的一个元素。
  11. **参数:**
  12. **axis** (int) - Log Softmax运算的axis,-1表示最后一个维度。默认值:-1。
  13. **输入:**
  14. - **x** (Tensor) - Log Softmax的输入,数据类型为float16或float32。
  15. **输出:**
  16. Tensor,数据类型和shape与`x`相同,值的范围在[-inf,0)。
  17. **异常:**
  18. - **TypeError** - `axis` 不是int。
  19. - **TypeError** - `x` 的数据类型既不是float16也不是float32。
  20. - **ValueError** - `axis` 不在[-len(x), len(x))范围中。
  21. **支持平台:**
  22. ``Ascend`` ``GPU`` ``CPU``
  23. **样例:**
  24. >>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
  25. >>> log_softmax = nn.LogSoftmax()
  26. >>> output = log_softmax(x)
  27. >>> print(output)
  28. [[-5.00672150e+00 -6.72150636e-03 -1.20067215e+01]
  29. [-7.00091219e+00 -1.40009127e+01 -9.12250078e-04]]