MCPcopy Create free account
hub / github.com/Anoise/WTFlib / __init__

Method __init__

LDPS_Graph/layers/Embed.py:9–22  ·  view source on GitHub ↗
(self, d_model, max_len=5000)

Source from the content-addressed store, hash-verified

7
8class PositionalEmbedding(nn.Module):
9 def __init__(self, d_model, max_len=5000):
10 super(PositionalEmbedding, self).__init__()
11 # Compute the positional encodings once in log space.
12 pe = torch.zeros(max_len, d_model).float()
13 pe.require_grad = False
14
15 position = torch.arange(0, max_len).float().unsqueeze(1)
16 div_term = (torch.arange(0, d_model, 2).float() * -(math.log(10000.0) / d_model)).exp()
17
18 pe[:, 0::2] = torch.sin(position * div_term)
19 pe[:, 1::2] = torch.cos(position * div_term)
20
21 pe = pe.unsqueeze(0)
22 self.register_buffer('pe', pe)
23
24 def forward(self, x):
25 return self.pe[:, :x.size(1)]

Callers

nothing calls this directly

Calls 1

__init__Method · 0.45

Tested by

no test coverage detected