python - tensorflow birectional lstm state dimension -
i using batch_size=100 , n_units=74. when following code run, rnn_state_fw
returns (1,2,100,74). can understand 100 batch_size , 74 state_size, 1 , 2 refer to?
forward_cell = tf.contrib.rnn.dropoutwrapper(tf.contrib.rnn.lstmcell(hidden_size,initializer=tf.random_uniform_initializer(-1.0,1.0),state_is_tuple=true),input_keep_prob=self.dropout_keep_prob_lstm_input,output_keep_prob=self.dropout_keep_prob_lstm_output) backward_cell = tf.contrib.rnn.dropoutwrapper(tf.contrib.rnn.lstmcell(hidden_size,initializer=tf.random_uniform_initializer(-1.0,1.0),state_is_tuple=true),input_keep_prob=self.dropout_keep_prob_lstm_input,output_keep_prob=self.dropout_keep_prob_lstm_output) forward_cell = tf.contrib.rnn.multirnncell([forward_cell _ in range(num_layers)],state_is_tuple=true) backward_cell = tf.contrib.rnn.multirnncell([backward_cell _ in range(num_layers)],state_is_tuple=true) initial_forward_state = forward_cell.zero_state(self.batch_size, tf.float32) initial_backward_state = backward_cell.zero_state(self.batch_size, tf.float32) rnn_output, rnn_state_fw,rnn_state_bw = tf.contrib.rnn.static_bidirectional_rnn(forward_cell,backward_cell, rnn_input,initial_state_fw=initial_forward_state,initial_state_bw=initial_backward_state,sequence_length=self.seq_lengths)
the lstmcell
objects set state_is_tuple=true
state lstmstatetuple
2 elements (c, m)
, c
cell state , m
hidden state (often denoted h
, e.g. in basiclstmcell
).
both c
, m
have shape (batch_size, num_units)
, , there num_layers
in multirnncell
. state dimensions directional cells (num_layers, 2, batch_size, num_units)
a walk-through of lstms of course colah's blog, , explanation of why have both hidden , cell state can found here.
Comments
Post a Comment