MCPcopy Create free account
hub / github.com/espnet/espnet / _source_mask

Method _source_mask

espnet2/tts/prodiff/prodiff.py:815–834  ·  view source on GitHub ↗

Make masks for self-attention. Args: ilens (LongTensor): Batch of lengths (B,). Returns: Tensor: Mask tensor for self-attention. dtype=torch.uint8 in PyTorch 1.2- dtype=torch.bool in PyTorch 1.2+ (including 1.2) Examp

(self, ilens: torch.Tensor)

Source from the content-addressed store, hash-verified

813 return hs
814
815 def _source_mask(self, ilens: torch.Tensor) -> torch.Tensor:
816 """Make masks for self-attention.
817
818 Args:
819 ilens (LongTensor): Batch of lengths (B,).
820
821 Returns:
822 Tensor: Mask tensor for self-attention.
823 dtype=torch.uint8 in PyTorch 1.2-
824 dtype=torch.bool in PyTorch 1.2+ (including 1.2)
825
826 Examples:
827 >>> ilens = [5, 3]
828 >>> self._source_mask(ilens)
829 tensor([[[1, 1, 1, 1, 1],
830 [1, 1, 1, 0, 0]]], dtype=torch.uint8)
831
832 """
833 x_masks = make_non_pad_mask(ilens).to(next(self.parameters()).device)
834 return x_masks.unsqueeze(-2)
835
836 def _reset_parameters(
837 self, init_type: str, init_enc_alpha: float, init_dec_alpha: float

Callers 1

_forwardMethod · 0.95

Calls 3

make_non_pad_maskFunction · 0.90
toMethod · 0.80
parametersMethod · 0.80

Tested by

no test coverage detected