-
Notifications
You must be signed in to change notification settings - Fork 4
/
models.py
37 lines (32 loc) · 1.29 KB
/
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
33
34
35
36
37
import basicNet
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
class HighwayFcModel(nn.Module):
def __init__(self, input_size, numLayers, activation='ReLU', gate_activation='Sigmoid', bias = -1.0):
super(HighwayFcModel,self).__init__()
self.highways = nn.ModuleList([basicNet.HighwayFcNet(input_size,numLayers,activation,gate_activation) for _ in range(numLayers)])
# self.linear = nn.Linear(input_size,output_size)
# self.dimChange = nn.Linear(inDims, input_size)
def forward(self, x):
# x = F.relu(self.dimChange(x))
for h in self.highways:
x = h(x)
# x = F.softmax(self.linear(x))
return x
class ConvModel1D(nn.Module):
def __init__(self, inputChannels, outputChannels, kernelWidths, usePool=False):
super(ConvModel1D, self).__init__()
self.bank = [nn.ModuleList([basicNet.ConvNet1D(inputChannels, outputChannels, kernelWidths[i]) for i in range(len(kernelWidths))])]
self.pool = nn.MaxPool1d(2, 1)
self.usePool = usePool
def forward(self, x):
#input should be of the form [N,C,L]: C = input channels; L = length of sequence
convOutput = Variable(torch.FloatTensor([]))
for c in self.bank:
y = c(x)
convOutput = torch.cat((convOutput, y), -1)
if self.usePool:
return self.pool(convOutput)
return convOutput