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

Class LearnedPositionalEncoding

mogen/models/utils/position_encoding.py:30–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28
29
30class LearnedPositionalEncoding(nn.Module):
31
32 def __init__(self, d_model, dropout=0.1, max_len=5000):
33 super(LearnedPositionalEncoding, self).__init__()
34 self.dropout = nn.Dropout(p=dropout)
35 self.pe = nn.Parameter(torch.randn(max_len, 1, d_model))
36
37 def forward(self, x):
38 x = x + self.pe[:x.shape[0]]
39 return self.dropout(x)
40
41
42def timestep_embedding(timesteps, dim, max_period=10000):

Callers 2

__init__Method · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected