我正在使用 Mac OS el capitán 并且我正在尝试遵循 quick start tutorial for 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
有没有人遇到过这个警告或有任何解决方法?
最佳答案
从警告中可以清楚地看出,您必须明确提及维度,因为 softmax 的隐式维度选择已被弃用。
就我而言,我使用的是 log_softmax
并且我已经更改了下面的代码行以包含维度。
torch.nn.functional.log_softmax(x) # This throws warning.
改为
torch.nn.functional.log_softmax(x, dim = 1) # This doesn't throw warning.
关于python-3.x - 用户警告 : Implicit dimension choice for log_softmax has been deprecated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49006773/