| 43 | |
| 44 | |
| 45 | class FixedEmbedding(nn.Module): |
| 46 | def __init__(self, c_in, d_model): |
| 47 | super(FixedEmbedding, self).__init__() |
| 48 | |
| 49 | w = torch.zeros(c_in, d_model).float() |
| 50 | w.require_grad = False |
| 51 | |
| 52 | position = torch.arange(0, c_in).float().unsqueeze(1) |
| 53 | div_term = (torch.arange(0, d_model, 2).float() |
| 54 | * -(math.log(10000.0) / d_model)).exp() |
| 55 | |
| 56 | w[:, 0::2] = torch.sin(position * div_term) |
| 57 | w[:, 1::2] = torch.cos(position * div_term) |
| 58 | |
| 59 | self.emb = nn.Embedding(c_in, d_model) |
| 60 | self.emb.weight = nn.Parameter(w, requires_grad=False) |
| 61 | |
| 62 | def forward(self, x): |
| 63 | return self.emb(x).detach() |
| 64 | |
| 65 | |
| 66 | class TemporalEmbedding(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected