(self, n_layer: int = 1, output_size: int = 1)
| 70 | |
| 71 | class MLP(nn.Module): |
| 72 | def __init__(self, n_layer: int = 1, output_size: int = 1) -> None: |
| 73 | super().__init__() |
| 74 | self.n_layer = n_layer |
| 75 | self.output_size = output_size |
| 76 | # input shape [batch_size, n_layer+output_size] |
| 77 | # each linear layer reduce the activation dim 1 size by 1. |
| 78 | self.mlp = torch.nn.Sequential( |
| 79 | *itertools.chain( |
| 80 | *( |
| 81 | [nn.Linear(i + output_size, i - 1 + output_size)] |
| 82 | + ([nn.ReLU()] if i != 1 else []) |
| 83 | for i in range(n_layer, 0, -1) |
| 84 | ) |
| 85 | ) |
| 86 | ) |
| 87 | |
| 88 | def forward(self, inputs: torch.Tensor) -> torch.Tensor: |
| 89 | return self.mlp(inputs) |
no outgoing calls
no test coverage detected