MCPcopy Create free account
hub / github.com/MarkFzp/act-plus-plus / PositionalEncoding

Class PositionalEncoding

train_actuator_network.py:252–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

250
251
252class 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
271def get_norm_stats(dataset_path_list):
272 all_commanded_speed = []

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected