MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / SinusoidalPosEmb

Class SinusoidalPosEmb

usr/diff/candidate_decoder.py:14–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13
14class SinusoidalPosEmb(nn.Module):
15 def __init__(self, dim):
16 super().__init__()
17 self.dim = dim
18
19 def forward(self, x):
20 device = x.device
21 half_dim = self.dim // 2
22 emb = math.log(10000) / (half_dim - 1)
23 emb = torch.exp(torch.arange(half_dim, device=device) * -emb)
24 emb = x[:, None] * emb[None, :]
25 emb = torch.cat((emb.sin(), emb.cos()), dim=-1)
26 return emb
27
28
29def Conv1d(*args, **kwargs):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected