MCPcopy Create free account
hub / github.com/FunAudioLLM/FunMusic / __init__

Method __init__

inspiremusic/transformer/embedding.py:37–57  ·  view source on GitHub ↗

Construct an PositionalEncoding object.

(self,
                 d_model: int,
                 dropout_rate: float,
                 max_len: int = 5000,
                 reverse: bool = False)

Source from the content-addressed store, hash-verified

35 """
36
37 def __init__(self,
38 d_model: int,
39 dropout_rate: float,
40 max_len: int = 5000,
41 reverse: bool = False):
42 """Construct an PositionalEncoding object."""
43 super().__init__()
44 self.d_model = d_model
45 self.xscale = math.sqrt(self.d_model)
46 self.dropout = torch.nn.Dropout(p=dropout_rate)
47 self.max_len = max_len
48
49 self.pe = torch.zeros(self.max_len, self.d_model)
50 position = torch.arange(0, self.max_len,
51 dtype=torch.float32).unsqueeze(1)
52 div_term = torch.exp(
53 torch.arange(0, self.d_model, 2, dtype=torch.float32) *
54 -(math.log(10000.0) / self.d_model))
55 self.pe[:, 0::2] = torch.sin(position * div_term)
56 self.pe[:, 1::2] = torch.cos(position * div_term)
57 self.pe = self.pe.unsqueeze(0)
58
59 def forward(self,
60 x: torch.Tensor,

Callers 5

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected