An error when I changed "gru" to "LSTM" in AttnDecoderRNN

Hi, I think this might be a basic question,
but could you tell me how to correct my code?

I used the seq2seq tutorial and adjust it.
I changed as following

def __init__
    #self.gru = nn.GRU(self.hidden_size, self.hidden_size)
    self.lstm = nn.LSTM(self.hidden_size, self.hidden_size)

def forward
    #output,hidden = self.gru(output,hidden)
    output, hidden = self.lstm(output, hidden)

Then this error happened,

 File "/.local/lib/python3.5/site-packages/torch/nn/modules/module.py", line 325, in __call__
    result = self.forward(*input, **kwargs)
  File "/.local/lib/python3.5/site-packages/torch/nn/modules/rnn.py", line 169, in forward
    output, hidden = func(input, self.all_weights, hx)
  File "/.local/lib/python3.5/site-packages/torch/nn/_functions/rnn.py", line 385, in forward
    return func(input, *fargs, **fkwargs)
  File "/.local/lib/python3.5/site-packages/torch/nn/_functions/rnn.py", line 245, in forward
    nexth, output = func(input, hidden, weight)
  File "/.local/lib/python3.5/site-packages/torch/nn/_functions/rnn.py", line 85, in forward
    hy, output = inner(input, hidden[l], weight[l])
  File "/.local/lib/python3.5/site-packages/torch/nn/_functions/rnn.py", line 114, in forward
    hidden = inner(input[i], hidden, *weight)
  File "/.local/lib/python3.5/site-packages/torch/nn/_functions/rnn.py", line 31, in LSTMCell
    hx, cx = hidden
ValueError: not enough values to unpack (expected 2, got 1)

LSTM has a pair (tuple) of (hidden, cell) where GRU/RNN only has hidden. Herr tge pair is hx, cx as part of a tuple hidden.
The documentation or examples show how to go about handling that.

Best regards

Thomas

Best regards

Thomas

1 Like