代码拉取完成,页面将自动刷新
torch.nn.functional.log_softmax(
input,
dim=None,
dtype=None
)
更多内容详见torch.nn.functional.log_softmax。
class mindspore.ops.log_softmax(
logits,
axis=-1,
)
更多内容详见mindspore.ops.log_softmax。
PyTorch:支持使用dim
参数和input
输入实现函数,对softmax的结果取对数。
MindSpore:支持使用axis
参数和logits
输入实现函数,对softmax的结果取对数。
分类 | 子类 | PyTorch | MindSpore | 差异 |
---|---|---|---|---|
参数 | 参数1 | input | logits | 功能一致,参数名不同 |
参数2 | dim | axis | 功能一致,参数名不同 | |
参数3 | dtype | - | PyTorch中用来指定输出Tensor的data type,MindSpore中没有该参数 |
import mindspore as ms
import mindspore.ops as ops
import torch
import numpy as np
# In MindSpore, we can define an instance of this class first, and the default value of the parameter axis is -1.
x = ms.Tensor(np.array([1, 2, 3, 4, 5]), ms.float32)
output1 = ops.log_softmax(x)
print(output1)
# Out:
# [-4.451912 -3.4519122 -2.4519122 -1.451912 -0.45191208]
x = ms.Tensor(np.array([[1, 2, 3, 4, 5], [5, 4, 3, 2, 1]]), ms.float32)
output2 = ops.log_softmax(x, axis=0)
print(output2)
# out:
# [[-4.01815 -2.126928 -0.6931472 -0.12692805 -0.01814996]
# [-0.01814996 -0.12692805 -0.6931472 -2.126928 -4.01815 ]]
# In torch, the input and dim should be input at the same time to implement the function.
input = torch.tensor(np.array([1.0, 2.0, 3.0, 4.0, 5.0]))
output3 = torch.nn.functional.log_softmax(input, dim=0)
print(output3)
# Out:
# tensor([-4.4519, -3.4519, -2.4519, -1.4519, -0.4519], dtype=torch.float64)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。