Reputation: 91
My question is to define bidirectional LSTM cells (fw_cell and bw_cell) in tensorflow we shall define fw_cell and bw_cell independently or the same?
Upvotes: 3
Views: 1159
Reputation: 66
you can create a function that defines each cell separately, you can use something like this:
def lstm_rnn_cell(num_units, dropout):
_cell = tf.nn.rnn_cell.LSTMCell(num_units,state_is_tuple = True)
_cell = tf.contrib.rnn.DropoutWrapper(_cell, output_keep_prob = dropout)
return _cell
and then you can do:
fw_cell = tf.nn.rnn_cell.MultiRNNCell([lstm_rnn_cell(rnn_size, dropout = dropout) for _ in range(num_layers)], state_is_tuple = True)
bw_cell = tf.nn.rnn_cell.MultiRNNCell([lstm_rnn_cell(rnn_size, dropout = dropout) for _ in range(num_layers)], state_is_tuple = True)
in this example I used a MultiRNNCell
so you can also define the number of layer for the given RNN by modifying num_layers
Upvotes: 5