(self, dynamic_ids, dynamic_lengths)
return concat_embeddings
input: relative id
        dynamic_ids: Batch_size * Field_size * Max_feature_size
        dynamic_lengths: Batch_size * Field_size
        return: Batch_size * Field_size * Embedding_size
input: relative id
        dynamic_ids: Batch_size * Field_size * Max_feature_size
        dynamic_lengths: Batch_size * Field_size
        return: Batch_size * Field_size * Embedding_size
input : relative id dynamic_ids : Batch_size * Field_size * Max_feature_size dynamic_lengths : Batch_size * Field_size return : Batch_size * Field_size * Embedding_size
def forward(self, dynamic_ids, dynamic_lengths):
        """
        input: relative id
        dynamic_ids: Batch_size * Field_size * Max_feature_size
        dynamic_lengths: Batch_size * Field_size
        return: Batch_size * Field_size * Embedding_size
        """
        concat_embeddings = []
        for i, key in enumerate(self.fnames):
            # B*M
            dynamic_ids_tensor = torch.LongTensor(np.array(dynamic_ids[key].values.tolist()))
            dynamic_lengths_tensor = torch.LongTensor(dynamic_lengths[key + '_length'].values.astype(int))
            if self.use_cuda:
                dynamic_ids_tensor = dynamic_ids_tensor.cuda()

            batch_size = dynamic_ids_tensor.size()[0]

            # embedding layer B*M*E
            dynamic_embeddings_tensor = self.embeddings[i](dynamic_ids_tensor)

            # average B*M*E --AVG--> B*E

            dynamic_lengths_tensor = dynamic_lengths_tensor.unsqueeze(1)
            mask = (torch.arange(dynamic_embeddings_tensor.size(1))[None, :] < dynamic_lengths_tensor[:, None]).type(torch.cuda.FloatTensor)
            mask = mask.squeeze(1).unsqueeze(2)
            dynamic_embedding = dynamic_embeddings_tensor.masked_fill(mask == 0, 0)
            dynamic_lengths_tensor[dynamic_lengths_tensor == 0] = 1
            dynamic_embedding = (dynamic_embedding.sum(dim=1) / dynamic_lengths_tensor.cuda()).unsqueeze(1)

            concat_embeddings.append(dynamic_embedding.view(batch_size, 1, self.embedding_size))
        # B*F*E
        concat_embeddings = torch.cat(concat_embeddings, 1)
        return concat_embeddings
def forward ( self , dynamic_ids , dynamic_lengths ) : concat_embeddings = [ ] for i , key in enumerate ( self . fnames ) : # B*M dynamic_ids_tensor = torch . LongTensor ( np . array ( dynamic_ids [ key ] . values . tolist ( ) ) ) dynamic_lengths_tensor = torch . LongTensor ( dynamic_lengths [ key + '_length' ] . values . astype ( int ) ) if self . use_cuda : dynamic_ids_tensor = dynamic_ids_tensor . cuda ( ) batch_size = dynamic_ids_tensor . size ( ) [ 0 ] # embedding layer B*M*E dynamic_embeddings_tensor = self . embeddings [ i ] ( dynamic_ids_tensor ) # average B*M*E --AVG--> B*E dynamic_lengths_tensor = dynamic_lengths_tensor . unsqueeze ( 1 ) mask = ( torch . arange ( dynamic_embeddings_tensor . size ( 1 ) ) [ None , : ] < dynamic_lengths_tensor [ : , None ] ) . type ( torch . cuda . FloatTensor ) mask = mask . squeeze ( 1 ) . unsqueeze ( 2 ) dynamic_embedding = dynamic_embeddings_tensor . masked_fill ( mask == 0 , 0 ) dynamic_lengths_tensor [ dynamic_lengths_tensor == 0 ] = 1 dynamic_embedding = ( dynamic_embedding . sum ( dim = 1 ) / dynamic_lengths_tensor . cuda ( ) ) . unsqueeze ( 1 ) concat_embeddings . append ( dynamic_embedding . view ( batch_size , 1 , self . embedding_size ) ) # B*F*E concat_embeddings = torch . cat ( concat_embeddings , 1 ) return concat_embeddings