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)
| 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 |
no test coverage detected