(self, src, memory_bank, encoder_final,
                           with_cache=False)
Init decoder state with last state of the encoder
Init decoder state with last state of the encoder
Init decoder state with last state of the encoder
def init_decoder_state(self, src, memory_bank, encoder_final,
                           with_cache=False):
        """ Init decoder state with last state of the encoder """
        def _fix_enc_hidden(hidden):
            # The encoder hidden is  (layers*directions) x batch x dim.
            # We need to convert it to layers x batch x (directions*dim).
            if self.bidirectional_encoder:
                hidden = torch.cat([hidden[0:hidden.size(0):2],
                                    hidden[1:hidden.size(0):2]], 2)
            return hidden

        if isinstance(encoder_final, tuple):  # LSTM
            return RNNDecoderState(self.hidden_size,
                                   tuple([_fix_enc_hidden(enc_hid)
                                          for enc_hid in encoder_final]))
        else:  # GRU
            return RNNDecoderState(self.hidden_size,
                                   _fix_enc_hidden(encoder_final))
def init_decoder_state ( self , src , memory_bank , encoder_final , with_cache = False ) : def _fix_enc_hidden ( hidden ) : # The encoder hidden is  (layers*directions) x batch x dim. # We need to convert it to layers x batch x (directions*dim). if self . bidirectional_encoder : hidden = torch . cat ( [ hidden [ 0 : hidden . size ( 0 ) : 2 ] , hidden [ 1 : hidden . size ( 0 ) : 2 ] ] , 2 ) return hidden if isinstance ( encoder_final , tuple ) : # LSTM return RNNDecoderState ( self . hidden_size , tuple ( [ _fix_enc_hidden ( enc_hid ) for enc_hid in encoder_final ] ) ) else : # GRU return RNNDecoderState ( self . hidden_size , _fix_enc_hidden ( encoder_final ) )