未定义名称“ rnn”

时间:2019-05-26 08:09:11

标签: python python-3.x pytorch chatbot

在建立聊天机器人时出现此错误。根本无法理解“ NameError”。有人可以帮忙吗?

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-91-27587b3519e0> in <module>
     98 # Loop through all the timesteps we have ::
     99 for t in range(max_target_len):   # max_target_len / max word we have = number of timesteps
--> 100     decoder_output, decoder_hidden = decoder(decoder_input, decoder_hidden, encoder_outputs)
    101     print("Decoder Output Shape: ", decoder_output.shape)
    102     print("Decoder Hidden Shape: ", decoder_hidden.shape)

~\Anaconda\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
    487             result = self._slow_forward(*input, **kwargs)
    488         else:
--> 489             result = self.forward(*input, **kwargs)
    490         for hook in self._forward_hooks.values():
    491             hook_result = hook(self, input, result)

<ipython-input-83-80b0205dcf70> in forward(self, input_step, last_hidden, encoder_outputs)
     69         context = context.squeeze(1)  #  transfers dim of context vector from (batch_size, 1, hidden_size) where (0,1,2) is there position vecotr. >> (batch_size, hidden_size)
     70 
---> 71         concat_input =torch.cat((rnn.output, context), 1)
     72         # concatiante rnn.output & context vector. 1 : concatinate along columns
     73         # concatenate them along 1st dimension, so we'll have (batch_size, hidden_size*2) because we are concatinating them along the columns

NameError: name 'rnn' is not defined

0 个答案:

没有答案