(self, enc_hiddens: torch.Tensor, source_lengths: List[int])
return enc_masks.to(self.device)
Generate sentence masks for encoder hidden states.

        @param enc_hiddens (Tensor): encodings of shape (b, src_len, 2*h), where b = batch size,
                                     src_len = max source length, h = hidden size.
        @param source_lengths (List[int]): List of actual lengths for each of the sentences in the batch.

        @returns enc_masks (Tensor): Tensor of sentence masks of shape (b, src_len),
                                    where src_len = max source length, h = hidden size.
Generate sentence masks for encoder hidden states.
Generate sentence masks for encoder hidden states .
def generate_sent_masks(self, enc_hiddens: torch.Tensor, source_lengths: List[int]) -> torch.Tensor:
        """ Generate sentence masks for encoder hidden states.

        @param enc_hiddens (Tensor): encodings of shape (b, src_len, 2*h), where b = batch size,
                                     src_len = max source length, h = hidden size.
        @param source_lengths (List[int]): List of actual lengths for each of the sentences in the batch.

        @returns enc_masks (Tensor): Tensor of sentence masks of shape (b, src_len),
                                    where src_len = max source length, h = hidden size.
        """
        enc_masks = torch.zeros(enc_hiddens.size(0), enc_hiddens.size(1), dtype=torch.float)
        for e_id, src_len in enumerate(source_lengths):
            enc_masks[e_id, src_len:] = 1
        return enc_masks.to(self.device)
def generate_sent_masks ( self , enc_hiddens : torch . Tensor , source_lengths : List [ int ] ) -> torch . Tensor : enc_masks = torch . zeros ( enc_hiddens . size ( 0 ) , enc_hiddens . size ( 1 ) , dtype = torch . float ) for e_id , src_len in enumerate ( source_lengths ) : enc_masks [ e_id , src_len : ] = 1 return enc_masks . to ( self . device )