Parameters: ----------- input_encoded: torch.Tensor [batch, series, time steps, embedding dimension] An embedding which will be modified by the position encoding. timesteps: torch.IntTensor [batch, series, time steps] or [batch, 1, time steps]
(self, input_encoded: torch.Tensor, timesteps: torch.IntTensor)
| 61 | self.register_buffer("pos_encoding", pos_encoding) |
| 62 | |
| 63 | def forward(self, input_encoded: torch.Tensor, timesteps: torch.IntTensor) -> torch.Tensor: |
| 64 | """ |
| 65 | Parameters: |
| 66 | ----------- |
| 67 | input_encoded: torch.Tensor [batch, series, time steps, embedding dimension] |
| 68 | An embedding which will be modified by the position encoding. |
| 69 | timesteps: torch.IntTensor [batch, series, time steps] or [batch, 1, time steps] |
| 70 | The time step for each entry in the input. |
| 71 | |
| 72 | Returns: |
| 73 | -------- |
| 74 | output_encoded: torch.Tensor [batch, series, time steps, embedding dimension] |
| 75 | The modified embedding. |
| 76 | """ |
| 77 | # Use the time difference between the first time step of each batch and the other time steps. |
| 78 | # min returns two outputs, we only keep the first. |
| 79 | min_t = timesteps.min(dim=1, keepdim=True)[0].min(dim=2, keepdim=True)[0] |
| 80 | delta_t = timesteps - min_t |
| 81 | |
| 82 | output_encoded = input_encoded + self.pos_encoding[delta_t] |
| 83 | return self.dropout(output_encoded) |
| 84 | |
| 85 | |
| 86 | class NormalizationIdentity: |
no outgoing calls