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
| --[[ | |
| 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 is a batched LSTM forward and backward pass | |
| """ | |
| import numpy as np | |
| import code | |
| class LSTM: | |
| @staticmethod | |
| def init(input_size, hidden_size, fancy_forget_bias_init = 3): |
NewerOlder