所以我很难理解Pytorch中关于收藏的一些术语。我总是遇到同样的错误
范围
我的张量是不正确的,当我试图搜索一个解决方案时,解释往往更加混乱。
下面是一个例子:
m = torch.nn.LogSoftmax(dim=1)
input = torch.tensor([0.3300, 0.3937, -0.3113, -0.2880])
output = m(input)
我看不出上面的代码有什么问题,我已经定义了
LogSoftmax
接受一维输入。所以根据我对其他编程语言的经验
[0.3300, 0.3937, -0.3113, -0.2880]
是单一维度。
以上触发以下错误
m(input)
:
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)
那是什么意思?
我通过了一个
一维的
张量,但它告诉我
[-1, 0], but got 1
.
-
一系列什么?
-
为什么比较维度
1
到
[-1, 0]
?
-
这两个数字是什么
[-1,0]
意思是?
我为这个错误寻找了一个解释,我发现像这样的链接对于我作为一个程序员来说毫无意义:
https://github.com/pytorch/pytorch/issues/5554#issuecomment-370456868
所以我可以通过在张量数据中添加另一个维度来修复上面的代码。
m = torch.nn.LogSoftmax(dim=1)
input = torch.tensor([[-0.3300, 0.3937, -0.3113, -0.2880]])
output = m(input)
好吧,但我不明白
[-1,0]
解释嵌套集合。
进一步的实验表明,以下方法同样有效:
m = torch.nn.LogSoftmax(dim=1)
input = torch.tensor([[0.0, 0.1], [1.0, 0.1], [2.0, 0.1]])
output = m(input)
所以
dim=1
意思是收藏,但我不明白这是什么意思
[-1,0]
.
当我尝试使用
LogSoftmax(dim=2)
m = torch.nn.LogSoftmax(dim=2)
input = torch.tensor([[0.0, 0.1], [1.0, 0.1], [2.0, 0.1]])
output = m(input)
上面给出了以下错误:
索引器错误:维度超出范围(应在范围[-2,1]内,但得到2)
又是困惑
dim=2
等于
[-2, 1]
,因为
1个
价值来自?
我可以通过
嵌套
收集另一个级别,但此时我不明白什么值
对数最大值
正在等待。
m = torch.nn.LogSoftmax(dim=2)
input = torch.tensor([[[0.0, 0.1]], [[1.0, 0.1]], [[2.0, 0.1]]])
output = m(input)
我被这个术语搞糊涂了
[-1,0]
和
[-2,1]
?
如果第一个值是嵌套深度,那么为什么
消极的
第二个数字是什么意思?
没有
错误代码
与此错误关联。所以很难找到关于这个问题的文件。似乎是
极其
常见的错误人们会感到困惑,我在Pythorch文档中找不到专门讨论它的任何东西。