This file contains hidden or 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
| --[[ | |
| Efficient LSTM in Torch using nngraph library. This code was optimized | |
| by Justin Johnson (@jcjohnson) based on the trick of batching up the | |
| LSTM GEMMs, as also seen in my efficient Python LSTM gist. | |
| --]] | |
| function LSTM.fast_lstm(input_size, rnn_size) | |
| local x = nn.Identity()() | |
| local prev_c = nn.Identity()() | |
| local prev_h = nn.Identity()() |
This file contains hidden or 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
| --[[ | |
| This layer expects an [n x d] Tensor and normalizes each | |
| row to have unit L2 norm. | |
| ]]-- | |
| local L2Normalize, parent = torch.class('nn.L2Normalize', 'nn.Module') | |
| function L2Normalize:__init() | |
| parent.__init(self) | |
| end | |
| function L2Normalize:updateOutput(input) |
This file contains hidden or 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
| """ | |
| Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy) | |
| BSD License | |
| """ | |
| import numpy as np | |
| # data I/O | |
| data = open('input.txt', 'r').read() # should be simple plain text file | |
| chars = list(set(data)) | |
| data_size, vocab_size = len(data), len(chars) |