I am trying to convert the following Keras code into pure Tensorflow but I have trouble adding a dense layer to every timestep of the bidirectional RNN output:
Here is the Keras code in question:
self.model = Sequential()
self.model.add(Bidirectional(LSTM(nr_out, return_sequences=True,
dropout_W=dropout, dropout_U=dropout),
input_shape=(max_length, nr_out)))
self.model.add(TimeDistributed(Dense(nr_out, activation='relu', init='he_normal')))
self.model.add(TimeDistributed(Dropout(0.2)))
Here is the initial tensorflow code:
lstm_cell_fwd = rnn.BasicLSTMCell(num_hidden, forget_bias=1.0)
lstm_cell_bwd = rnn.BasicLSTMCell(num_hidden, forget_bias=1.0)
outputs, output_state_fw, output_state_bw = rnn.static_bidirectional_rnn(lstm_cell_fwd, lstm_cell_bwd, inputs=sequence, dtype=tf.float64)
Generally if I only wanted to predict on the last state I would do something like:
logits = tf.matmul(outputs[-1], weights['out']) + biases['out']
What is the best way to express the TimeDistributed layer in Tensorflow?