Last active
March 23, 2018 02:49
-
-
Save tomgrek/a3c381746a4be6906185c08e83ffad96 to your computer and use it in GitHub Desktop.
2_b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BotBrain(nn.Module): | |
def __init__(self): | |
super().__init__() | |
self.embedding = nn.Embedding(len(words), 10) | |
self.rnn = nn.LSTM(20, 30, 2, dropout=0.5) | |
self.h = (Variable(torch.zeros(2, 1, 30)).cuda(), Variable(torch.zeros(2, 1, 30))) | |
self.l_out = nn.Linear(30, len(words)) | |
def forward(self, cs): | |
inp = (self.embedding(cs)).view(1, -1) | |
outp,h = self.rnn(inp.view(1,1,-1), self.h) #rnn requires 3 dims | |
out = F.log_softmax(self.l_out(outp), dim=-1).view(-1, len(words)) | |
return out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment