MCPcopy Create free account
hub / github.com/TeleHuman/TextOp / PositionalEncoding

Class PositionalEncoding

TextOpRobotMDAR/robotmdar/model/mld_denoiser.py:193–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191
192
193class PositionalEncoding(nn.Module):
194
195 def __init__(self, d_model, dropout=0.1, max_len=5000):
196 super(PositionalEncoding, self).__init__()
197 self.dropout = nn.Dropout(p=dropout)
198
199 pe = torch.zeros(max_len, d_model)
200 position = torch.arange(0, max_len, dtype=torch.float).unsqueeze(1)
201 div_term = torch.exp(
202 torch.arange(0, d_model, 2).float() * (-np.log(10000.0) / d_model))
203 pe[:, 0::2] = torch.sin(position * div_term)
204 pe[:, 1::2] = torch.cos(position * div_term)
205 pe = pe.unsqueeze(0).transpose(0, 1)
206
207 self.register_buffer('pe', pe)
208
209 def forward(self, x):
210 # not used in the final model
211 x = x + self.pe[:x.shape[0], :]
212 return self.dropout(x)
213
214
215class TimestepEmbedder(nn.Module):

Callers 2

__init__Method · 0.70
__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected