tf.nn.rnn_cell.MultiRNNCell([list RNNcell], state_is_tuple=True).这个函数里面主要这两个参数,第一个参数就是输入的RNN实例形成的列表,第二个参数就是让状态是一个元祖,官方推荐就是用True。
例如:
import tensorflow as tf;
import numpy as np;
X = tf.random_normal(shape=[3,5,6], dtype=tf.float32)
X = tf.reshape(X, [-1, 5, 6])
cell = tf.nn.rnn_cell.BasicLSTMCell(10)#也可以换成别的,比如GRUCell,BasicRNNCell等等
lstm_multi = tf.nn.rnn_cell.MultiRNNCell([cell]*2, state_is_tuple=True)
state = lstm_multi.zero_state(3, tf.float32)
output, state = tf.nn.dynamic_rnn(lstm_multi, X, initial_state=state, time_major=False)
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
print output.get_shape()
print sess.run(state)