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

Class SinusoidalPosEmb

usr/diff/net.py:32–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31
32class SinusoidalPosEmb(nn.Module):
33 def __init__(self, dim):
34 super().__init__()
35 self.dim = dim
36
37 def forward(self, x):
38 device = x.device
39 half_dim = self.dim // 2
40 emb = math.log(10000) / (half_dim - 1)
41 emb = torch.exp(torch.arange(half_dim, device=device) * -emb)
42 emb = x[:, None] * emb[None, :]
43 emb = torch.cat((emb.sin(), emb.cos()), dim=-1)
44 return emb
45
46
47def Conv1d(*args, **kwargs):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected