An Example for tf.nn.static_bidirectional_rnn

import tensorflow as tf
import numpy as np

fw_cell = tf.nn.rnn_cell.BasicRNNCell(128)
bw_cell = tf.nn.rnn_cell.BasicRNNCell(256)
inputs = tf.Variable(tf.random_normal([100, 40, 300]))  # [batch_size,timestep,embedding_dim]
inputs = tf.unstack(inputs, 40, axis=1) #
# inputs is a list
print(np.array(inputs).shape) # (40, )
outputs, fw, bw = tf.nn.static_bidirectional_rnn(fw_cell, bw_cell, inputs, dtype=tf.float32)
print(len(outputs)) # 40
#outputs is a list, timestep * batch_size * 384
print(outputs[0].shape)# (100,384),384=128+256
print(outputs[1].shape)# (100,384)
print(fw.shape) #  (100,128)
print(bw.shape) # (100, 256)

The result is:

(40,)
40
(100, 384)
(100, 384)
(100, 128)
(100, 256)

, ,