The decoder’s forward function is like this:  def forward(self,input,length,src_input,hidden_sent,hidden_word):

   batch_size, num_sent, num_word = input.size()
    output_list = []
    for sent_index in range(num_sent):
        #prepare the input for the word-level rnn
        indexed_sent_input, indexed_length = input[:,sent_index],length[:,sent_index]
        embedding_one_sent = self.embedding(indexed_sent_input)
        rnn_h_sent = hidden_sent[0].unsqueeze(1)
        rnn_h_sent_expand = rnn_h_sent.expand(batch_size,num_word,self.num_hidden_sent)
        word_input = torch.cat([embedding_one_sent,rnn_h_sent_expand],dim=2)
        rnn_result_word,hidden_word = self.rnn_word(word_input,hidden_word)
        rnn_result_last,rnn_result_sent = collect_last_hidden(rnn_result_word,indexed_length)
        attentioned_src_input = self.attention(src_input,rnn_h_sent)
        sent_input = torch.cat([rnn_result_last,attentioned_src_input],dim=1)
        hidden_sent = self.rnn_cell_sent(sent_input,hidden_sent)
        output_list.append(rnn_result_sent)
    output_list = [self.linear(output) for output in output_list]
    return output_list,hidden_sent,hidden_word