Created
July 30, 2020 03:39
-
-
Save wcneill/cc1037f337f54bf8fd31934a797ba15a to your computer and use it in GitHub Desktop.
Medium lstm article
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
input_size = 1 # The number of variables in your sequence data. | |
n_hidden = 100 # The number of hidden nodes in the LSTM layer. | |
n_layers = 2 # The total number of LSTM layers to stack. | |
out_size = 1 # The size of the output you desire from your RNN. | |
lstm = nn.LSTM(input_size, n_hidden, n_layers, batch_first=True) | |
linear = nn.Linear(n_hidden, 1) | |
# Data Flow Protocol: | |
# 1. network input shape: (batch_size, seq_length, num_features) | |
# 2. LSTM output shape: (batch_size, seq_length, hidden_size) | |
# 3. Linear input shape: (batch_size * seq_length, hidden_size) | |
# 4. Linear output: (batch_size * seq_length, out_size) | |
x = get_batches(data) | |
lstm_out, hs = lstm(x, hs) | |
linear_in = lstm_out.reshape(-1, hidden_size) | |
linear_out = linear(linear_in) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment