-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel.py
More file actions
48 lines (38 loc) · 1.46 KB
/
Model.py
File metadata and controls
48 lines (38 loc) · 1.46 KB
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
38
39
40
41
42
43
44
45
46
47
48
from torch.distributions.categorical import Categorical
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
import matplotlib.pyplot as plt
from utils import *
import pandas as pd
class Classifier(nn.Module):
def __init__(self,inputs, hidden_size, n_layers, o_size):
super(Classifier, self).__init__()
self.inputs = inputs
self.hidden_size = hidden_size
self.fc1 = nn.Linear(inputs, hidden_size)
self.fc2 = nn.Linear(hidden_size, hidden_size)
self.fc3 = nn.Linear(hidden_size, 1)
def forward(self, x):
x_1 = F.relu(self.fc1(x))
x_2 = F.relu(self.fc2(x_1))
x = F.sigmoid(self.fc3(x_2))
return x
class RNN(nn.Module):
def __init__(self, input_size, hidden_size, n_layers,output_size):
super(RNN, self).__init__()
self.hidden_size = torch.zeros(1,hidden_size)
self.i2h = nn.Linear(input_size + hidden_size, hidden_size)
self.i2o = nn.Linear(input_size + hidden_size, output_size)
self.softmax = nn.LogSoftmax(dim=1)
def forward(self, X):
#print(X.shape)
#print(hidden.shape)
combined = torch.cat((X, self.hidden_size), 1)
self.hidden = self.i2h(combined)
output = self.i2o(combined)
output = F.sigmoid(output)#self.softmax(output)
return output, self.hidden
def initHidden(self):
return torch.zeros(len(X_train),HIDDEN_SIZE)