我正在使用 Mac OS el capitán,我正在尝试遵循 OpenNMT pytorch 版本的快速入门教程。 在训练步骤中,我收到以下警告消息:
OpenNMT-py/onmt/modules/GlobalAttention.py:177: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.
align_vectors = self.sm(align.view(batch*targetL, sourceL))
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/torch/nn/modules/container.py:67: UserWarning: Implicit dimension choice for log_softmax has been deprecated. Change the call to include dim=X as an argument.
input = module(input)
第 1 步:预处理数据(按预期工作)
python preprocess.py -train_src data/src-train.txt -train_tgt data/tgt-train.txt -valid_src data/src-val.txt -valid_tgt data/tgt-val.txt -save_data data/demo
第2步:训练模型(产生警告消息)
python train.py -data data/demo -save_model demo-model
有人遇到过这个警告或者有解决办法吗?
torch.nn.functional.log_softmax(x, -1)
就我而言,我正在使用
log_softmax
并且我已更改以下代码行以包含尺寸。
torch.nn.functional.log_softmax(x) # This throws warning.
更改为
torch.nn.functional.log_softmax(x, dim = 1) # This doesn't throw warning.
softmax 的隐式维度选择已被弃用。当我在没有
dim
参数的情况下运行 Softmax()
时,如下所示:
import torch
from torch import nn
my_tensor = torch.tensor([8., -3., 0., -5.])
softmax = nn.Softmax() # No `dim` argument
softmax(input=my_tensor) # Warning
所以,我将 dim
argumnet 设置为
Softmax()
,然后我就可以得到如下所示的结果。 *
dim
应设置为
Softmax()
:
import torch
from torch import nn
my_tensor = torch.tensor([8., -3., 0., -5.])
softmax = nn.Softmax(dim=0) # Here
softmax(input=my_tensor)
# tensor([9.9965e-01, 1.6696e-05, 3.3534e-04, 2.2595e-06])