MCPcopy Create free account
hub / github.com/MotrixLab/insactor / PositionalEncoding

Class PositionalEncoding

diffplanner/models/rnns/t2m_bigru.py:48–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46
47
48class PositionalEncoding(nn.Module):
49
50 def __init__(self, d_model, max_len=300):
51 super(PositionalEncoding, self).__init__()
52
53 pe = torch.zeros(max_len, d_model)
54 position = torch.arange(0, max_len, dtype=torch.float).unsqueeze(1)
55 div_term = torch.exp(torch.arange(0, d_model, 2).float() * (-math.log(10000.0) / d_model))
56 pe[:, 0::2] = torch.sin(position * div_term)
57 pe[:, 1::2] = torch.cos(position * div_term)
58 # pe = pe.unsqueeze(0).transpose(0, 1)
59 self.register_buffer('pe', pe)
60
61 def forward(self, pos):
62 return self.pe[pos]
63
64
65@SUBMODULES.register_module()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected