(self, src, lengths=None)
return encoder_final, memory_bank
See :obj:`EncoderBase.forward()`
See :obj:`EncoderBase.forward()`
See : obj : EncoderBase . forward ()
def forward(self, src, lengths=None):
        "See :obj:`EncoderBase.forward()`"
        self._check_args(src, lengths)

        emb = self.embeddings(src)

        s_len, batch, emb_dim = emb.size() # (185 16 128), s_len is changeable.

        packed_emb = emb
        if lengths is not None and not self.no_pack_padded_seq:
            # Lengths data is wrapped inside a Tensor.
            lengths = lengths.view(-1).tolist()
            packed_emb = pack(emb, lengths)

        memory_bank, encoder_final = self.rnn(packed_emb) # output, (hidden, cell), unpack using pad_packed_sequence()
        # memory_bank is the output
        # self.rnn is a LSTM(128, 256, bidirectional=True) # input dim; output dim;

        # print('Hidden..', encoder_final[0].size(), encoder_final[1].size()) # both torch.Size([2, 16, 256]), 2 directions.

        if lengths is not None and not self.no_pack_padded_seq:
            memory_bank = unpack(memory_bank)[0]

        if self.use_bridge:
            encoder_final = self._bridge(encoder_final)

        print('Out..', memory_bank.size())
        #Out.. torch.Size([16, 512]) torch.Size([16, 512]) : two dir?

        return encoder_final, memory_bank
def forward ( self , src , lengths = None ) : self . _check_args ( src , lengths ) emb = self . embeddings ( src ) s_len , batch , emb_dim = emb . size ( ) # (185 16 128), s_len is changeable. packed_emb = emb if lengths is not None and not self . no_pack_padded_seq : # Lengths data is wrapped inside a Tensor. lengths = lengths . view ( - 1 ) . tolist ( ) packed_emb = pack ( emb , lengths ) memory_bank , encoder_final = self . rnn ( packed_emb ) # output, (hidden, cell), unpack using pad_packed_sequence() # memory_bank is the output # self.rnn is a LSTM(128, 256, bidirectional=True) # input dim; output dim; # print('Hidden..', encoder_final[0].size(), encoder_final[1].size()) # both torch.Size([2, 16, 256]), 2 directions. if lengths is not None and not self . no_pack_padded_seq : memory_bank = unpack ( memory_bank ) [ 0 ] if self . use_bridge : encoder_final = self . _bridge ( encoder_final ) print ( 'Out..' , memory_bank . size ( ) ) #Out.. torch.Size([16, 512]) torch.Size([16, 512]) : two dir? return encoder_final , memory_bank