nn.CorssEntropyLoss 文档示例不正确?

nn.CorssEntropyLoss documentation example is not correct?

测试了 the documentation nn.CrossEntropyLoss 的例子。好像不行。

loss = nn.CrossEntropyLoss()

input = torch.randn(3, 5, requires_grad=True)
target = torch.randn(3, 5).softmax(dim=1)
output = loss(input, target)
print(output)

错误:

RuntimeError: 1D target tensor expected, multi-target not supported

您可能需要升级手电筒版本。

pip install torch --upgrade