Are your environment and fastai library up-to-date ?
Try:
git pull
conda env update
I’m thinking the problem is probably because of the pytorch version.
Run this to see your pytorch version. Fastai is not ready yet to use with the latest pytorch 0.4. So maybe there are some bugs in the updating.
Thank you for the hint! I have modified the code so that it works with pytorch 0.4 now. It’s the forward method that needs to be changed a little bit. I have pasted my code here in case somebody else might find it useful:
class CharLoopConcatModel2(nn.Module):
def __init__(self, vocab_size, n_fac):
super().__init__()
self.e = nn.Embedding(vocab_size, n_fac)
self.l_in = nn.Linear(n_fac, n_hidden)
self.l_hidden = nn.Linear(2*n_hidden, n_hidden)
self.l_out = nn.Linear(n_hidden, vocab_size)
def forward(self, *cs):
if cs[0].size():
bs = cs[0].size(0)
h = V(torch.zeros(bs, n_hidden))
else:
h = V(torch.zeros(n_hidden))
for c in cs:
inp = F.relu(self.l_in(self.e(c)))
h = F.tanh(self.l_hidden(torch.cat((h, inp), -1)))
return F.log_softmax(self.l_out(h), dim=-1)
In function get_next change idxs = T(np.array([char_indices[c] for c in inp]))
to idxs = T(np.array([char_indices[c] for c in inp])).view(1,-1)
Worked for me.
Unfortunately, I was not able to fix it with the code line posted above.
After checking/wrapping my head through the dimensions for hours I was able to find a solution that worked for me with pytorch 0.4: idxs = T(np.array([char_indices[c] for c in inp])).view(-1,1)
So in the end just a dimension mismatch with .view(). Maybe someone can verify this?