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
| from __future__ import print_function, division | |
| import numpy as np | |
| import tensorflow as tf | |
| import matplotlib.pyplot as plt | |
| num_epochs = 100 | |
| total_series_length = 50000 | |
| truncated_backprop_length = 15 | |
| state_size = 4 | |
| num_classes = 2 |
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
| cell = tf.nn.rnn_cell.LSTMCell(state_size, state_is_tuple=True) | |
| cell = tf.nn.rnn_cell.DropoutWrapper(cell, output_keep_prob=0.5) | |
| cell = tf.nn.rnn_cell.MultiRNNCell([cell] * num_layers, state_is_tuple=True) | |
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
| from __future__ import print_function, division | |
| import numpy as np | |
| import tensorflow as tf | |
| import matplotlib.pyplot as plt | |
| num_epochs = 100 | |
| total_series_length = 50000 | |
| truncated_backprop_length = 15 | |
| state_size = 4 | |
| num_classes = 2 |
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
| losses = tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels) | |
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
| logits_series = tf.unpack(tf.reshape(logits, [batch_size, truncated_backprop_length, num_classes]), axis=1) | |
| predictions_series = [tf.nn.softmax(logit) for logit in logits_list] | |
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
| logits = tf.matmul(states_series, W2) + b2 #Broadcasted addition | |
| labels = tf.reshape(batchY_placeholder, [-1]) |
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
| states_series, current_state = tf.nn.dynamic_rnn(cell, tf.expand_dims(batchX_placeholder, -1), initial_state=rnn_tuple_state) | |
| states_series = tf.reshape(states_series, [-1, state_size]) | |
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
| from __future__ import print_function, division | |
| import numpy as np | |
| import tensorflow as tf | |
| import matplotlib.pyplot as plt | |
| num_epochs = 100 | |
| total_series_length = 50000 | |
| truncated_backprop_length = 15 | |
| state_size = 4 | |
| num_classes = 2 |
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
| # Forward passes | |
| cell = tf.nn.rnn_cell.LSTMCell(state_size, state_is_tuple=True) | |
| cell = tf.nn.rnn_cell.MultiRNNCell([cell] * num_layers, state_is_tuple=True) | |
| states_series, current_state = tf.nn.rnn(cell, inputs_series, initial_state=rnn_tuple_state) | |
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
| state_per_layer_list = tf.unpack(init_state, axis=0) | |
| rnn_tuple_state = tuple( | |
| [tf.nn.rnn_cell.LSTMStateTuple(state_per_layer_list[idx][0], state_per_layer_list[idx][1]) | |
| for idx in range(num_layers)] | |
| ) | |
NewerOlder