(self, src, src_sents=None, lengths=None)
return encoder_final, memory_bank, sent_output
forward_original
forward_original
forward_original
def forward(self, src, src_sents=None, lengths=None):
        "forward_original"
        #print ('Original!')
        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(), encoder_final is the last state, a list (contains the batch)
        # encoder_final size: a list, len is the batch size; for each item, size [2, 2, 256]


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

        # print ('forwarding... src_sents',src_sents)

        # get sentence embedding
        sent_output = self.build_sentence_layer(memory_bank,src_sents)
        # sent_output size: torch.Size([9, 2, 512])
        # print ('We need...!!!',src_sents.size(),src_sents)


        if lengths is not None and not self.no_pack_padded_seq:
            memory_bank = unpack(memory_bank)[0]
        # memory_bank size torch.Size([200, 2, 512])


        # encoder_final: a tuple of 2 (batch size)
        # each of it has the size of torch.Size([2, 2, 256])

        if self.use_bridge:
            encoder_final = self._bridge(encoder_final)
        # encoder_final same shape as before

        return encoder_final, memory_bank, sent_output
def forward ( self , src , src_sents = None , lengths = None ) : #print ('Original!') 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(), encoder_final is the last state, a list (contains the batch) # encoder_final size: a list, len is the batch size; for each item, size [2, 2, 256] # memory_bank is the output # output, (hidden, cell), unpack using pad_packed_sequence() # self.rnn is a LSTM(128, 256, bidirectional=True) # input dim; output dim; # print ('forwarding... src_sents',src_sents) # get sentence embedding sent_output = self . build_sentence_layer ( memory_bank , src_sents ) # sent_output size: torch.Size([9, 2, 512]) # print ('We need...!!!',src_sents.size(),src_sents) if lengths is not None and not self . no_pack_padded_seq : memory_bank = unpack ( memory_bank ) [ 0 ] # memory_bank size torch.Size([200, 2, 512]) # encoder_final: a tuple of 2 (batch size) # each of it has the size of torch.Size([2, 2, 256]) if self . use_bridge : encoder_final = self . _bridge ( encoder_final ) # encoder_final same shape as before return encoder_final , memory_bank , sent_output