| 250 | |
| 251 | |
| 252 | class PositionalEncoding(nn.Module): |
| 253 | def __init__(self, d_model: int, dropout: float = 0.1, max_len: int = 5000): |
| 254 | super().__init__() |
| 255 | self.dropout = nn.Dropout(p=dropout) |
| 256 | position = torch.arange(max_len).unsqueeze(1) |
| 257 | div_term = torch.exp(torch.arange(0, d_model, 2) * (-math.log(10000.0) / d_model)) |
| 258 | pe = torch.zeros(max_len, 1, d_model) |
| 259 | pe[:, 0, 0::2] = torch.sin(position * div_term) |
| 260 | pe[:, 0, 1::2] = torch.cos(position * div_term) |
| 261 | self.register_buffer('pe', pe) |
| 262 | |
| 263 | def forward(self, x): |
| 264 | """ |
| 265 | Arguments: |
| 266 | x: Tensor, shape ``[seq_len, batch_size, embedding_dim]`` |
| 267 | """ |
| 268 | x = x + self.pe[:x.size(0)] |
| 269 | return self.dropout(x) |
| 270 | |
| 271 | def get_norm_stats(dataset_path_list): |
| 272 | all_commanded_speed = [] |