-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
32 lines (24 loc) · 836 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Models for selector implementation."""
import torch.nn as nn
class SelectiveNet(nn.Module):
"""Implements a feed-forward MLP."""
def __init__(
self,
input_dim,
hidden_dim,
num_layers,
dropout=0.0,
):
super(SelectiveNet, self).__init__()
self.input_dim = input_dim
self.hidden_dim = hidden_dim
self.num_layers = num_layers
layers = [nn.Linear(input_dim, hidden_dim), nn.ReLU()]
for _ in range(num_layers):
layers.append(nn.Dropout(dropout))
layers.append(nn.Linear(hidden_dim, hidden_dim))
layers.append(nn.ReLU())
layers.extend([nn.Dropout(dropout), nn.Linear(hidden_dim, 1)])
self.net = nn.Sequential(*layers)
def forward(self, x):
return self.net(x).view(-1)