Hi all. Working on my first PyTorch project!
I am embedding an input vector and feeding it and an initial hidden state into the GRU cell. Here is the code:
class Encoder(nn.Module):
def __init__(self, input_size, embedding_size=500, hidden_size=1000):
super(Encoder, self).__init__()
self.hidden_size = hidden_size
self.embedding = nn.Embedding(input_size, embedding_size)
self.gru = nn.GRU(embedding_size, hidden_size, 1)
def forward(self, input, hidden):
embedded = self.embedding(input).view(1, 1, -1)
output, hidden_state = self.gru(embedded, hidden)
return output, hidden_state
Unfortunately, the code breaks at the second line of forward
. I am able to embed the input just fine! The size after the embedding is (1, 1, 500). However, I get this error when GRU tries to run:
TypeError: addmm_ received an invalid combination of arguments - got (int, int, torch.LongTensor, torch.FloatTensor), but expected one of:
This is followed by a long list of acceptable inputs. However, I never touch the input that is in question (the input which is torch.FloatTensor
, which should be torch.LongTensor
); I only pass GRU the first of the two Tensors, which has correct type! Any idea on what may be going wrong?