(self, x)
| 28 | self.W3 = nn.Linear(num_snapshots*hidden_size, 3) |
| 29 | |
| 30 | def forward(self, x): |
| 31 | # x.shape = [batch_size, num_snapshots, num_features] |
| 32 | x = x.squeeze(1) |
| 33 | |
| 34 | X_tilde = self.W1(x) |
| 35 | # alpha.shape = [batch_size, num_snapshots, num_features] |
| 36 | |
| 37 | alpha = self.softmax(X_tilde) |
| 38 | # alpha.shape = [batch_size, num_snapshots, num_features] |
| 39 | |
| 40 | alpha = torch.mean(alpha, dim=2) |
| 41 | # alpha.shape = [batch_size, num_snapshots] |
| 42 | |
| 43 | x_tilde = torch.einsum('ij,ijk->ijk', [alpha, x]) |
| 44 | # x_tilde.shape = [batch_size, num_snapshots, num_features] |
| 45 | |
| 46 | H, _ = self.gru(x_tilde) |
| 47 | # o.shape = [batch_size, num_snapshots, hidden_size] |
| 48 | |
| 49 | H_tilde = self.W2(H) |
| 50 | # o.shape = [batch_size, num_snapshots, hidden_size] |
| 51 | |
| 52 | beta = self.softmax(H_tilde) |
| 53 | # o.shape = [batch_size, num_snapshots, hidden_size] |
| 54 | |
| 55 | beta = torch.mean(beta, dim=2) |
| 56 | # beta.shape = [batch_size, num_snapshots] |
| 57 | |
| 58 | h_tilde = torch.einsum('ij,ijk->ijk', [beta, H]) |
| 59 | # h_tilde.shape = [batch_size, num_snapshots, hidden_size] |
| 60 | |
| 61 | h_tilde = torch.flatten(h_tilde, start_dim=1) |
| 62 | # h_tilde.shape = [batch_size, hidden_size*num_snapshots] |
| 63 | |
| 64 | logits = self.W3(h_tilde) |
| 65 | # out.shape = [batch_size, 3] |
| 66 | |
| 67 | return logits |
nothing calls this directly
no outgoing calls
no test coverage detected