ルアテーブルに異なる次元のテンソルを挿入しようとしています。しかし、挿入は最後のテンソルをテーブルのすべての前の要素に書き込んでいます。トーチ異なる次元のテンソルをテーブルに挿入する
MWE:
require 'nn';
char = nn.LookupTable(100,10,0,1)
charRep = nn.Sequential():add(char):add(nn.Squeeze())
c = {}
c[1] = torch.IntTensor(5):random(1,100)
c[2] = torch.IntTensor(2):random(1,100)
c[3] = torch.IntTensor(3):random(1,100)
--This works fine
print(c)
charFeatures = {}
for i=1,3 do
charFeatures[i] = charRep:forward(c[i])
--table.insert(charFeatures, charRep:forward(c[i]))
-- No difference when table.insert is used
end
--This fails
print(charFeatures)
はたぶん私はテーブルはLuaの中でどのように機能するかを理解していません。しかし、このコードは最後のテンソルを前のすべてのcharFeatures
要素にコピーします。
ありがとうございました。それは期待どおりに動作します:) –