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

Class PositionalEncoding

mogen/models/rnns/t2m_bigru.py:51–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected