Add positional encoding. Args: x (torch.Tensor): Input. Its shape is (batch, time, ...) offset (int, torch.tensor): position offset Returns: torch.Tensor: Encoded tensor. Its shape is (batch, time, ...) torch.Tensor: for compatibility
(self,
x: torch.Tensor,
offset: Union[int, torch.Tensor] = 0)
| 59 | self.register_buffer("pe", pe) |
| 60 | |
| 61 | def forward(self, |
| 62 | x: torch.Tensor, |
| 63 | offset: Union[int, torch.Tensor] = 0) \ |
| 64 | -> Tuple[torch.Tensor, torch.Tensor]: |
| 65 | """Add positional encoding. |
| 66 | |
| 67 | Args: |
| 68 | x (torch.Tensor): Input. Its shape is (batch, time, ...) |
| 69 | offset (int, torch.tensor): position offset |
| 70 | |
| 71 | Returns: |
| 72 | torch.Tensor: Encoded tensor. Its shape is (batch, time, ...) |
| 73 | torch.Tensor: for compatibility to RelPositionalEncoding |
| 74 | """ |
| 75 | |
| 76 | pos_emb = self.position_encoding(offset, x.size(1), False) |
| 77 | x = x * self.xscale + pos_emb |
| 78 | return self.dropout(x), self.dropout(pos_emb) |
| 79 | |
| 80 | def position_encoding(self, |
| 81 | offset: Union[int, torch.Tensor], |
nothing calls this directly
no test coverage detected