Last active
August 9, 2018 23:40
-
-
Save Myeongjoon/5d8af43108f9d0eca4cab8c2430818d6 to your computer and use it in GitHub Desktop.
RNN States
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
# Weights and bias for input and hidden layer | |
with tf.name_scope('rnn_weights'): | |
with tf.name_scope("W_x"): | |
Wx = tf.Variable(tf.zeros([element_size, hidden_layer_size])) | |
variable_summaries(Wx) | |
with tf.name_scope("W_h"): | |
Wh = tf.Variable(tf.zeros([hidden_layer_size, hidden_layer_size])) | |
variable_summaries(Wh) | |
with tf.name_scope("Bias"): | |
b_rnn = tf.Variable(tf.zeros([hidden_layer_size])) | |
variable_summaries(b_rnn) | |
def rnn_step(previous_hidden_state, x): | |
current_hidden_state = tf.tanh( | |
tf.matmul(previous_hidden_state, Wh) + | |
tf.matmul(x, Wx) + b_rnn) | |
return current_hidden_state | |
initial_hidden = tf.zeros([batch_size, hidden_layer_size]) | |
# Getting all state vectors across time | |
all_hidden_states = tf.scan(rnn_step, | |
processed_input, | |
initializer=initial_hidden, | |
name='states') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment