go00od commited on
Commit
6039c68
1 Parent(s): 2e8c165

Upload model_def.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. model_def.py +24 -0
model_def.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch.nn as nn
2
+ import torch.nn.functional as F
3
+ import torch
4
+
5
+ class RNN(nn.Module):
6
+ def __init__(self, input_size, hidden_size, output_size):
7
+ super(RNN, self).__init__()
8
+
9
+ self.hidden_size = hidden_size
10
+
11
+ self.i2h = nn.Linear(input_size, hidden_size)
12
+ self.h2h = nn.Linear(hidden_size, hidden_size)
13
+ self.h2o = nn.Linear(hidden_size, output_size)
14
+ self.softmax = nn.LogSoftmax(dim=1)
15
+
16
+ def forward(self, input, hidden):
17
+ hidden = F.tanh(self.i2h(input) + self.h2h(hidden))
18
+ output = self.h2o(hidden)
19
+ output = self.softmax(output)
20
+ return output, hidden
21
+
22
+ def initHidden(self):
23
+ return torch.zeros(1, self.hidden_size)
24
+