在张量流中连接两个 RNN 状态



我正在尝试组合两个RNN状态,并在tensorflow中通过另一个RNN运行它们。这是我正在尝试处理的代码片段:

import numpy as np
c = [1, 2, 3,4, 5, 6,2, 3,4]
u = [4,5,6,6,7,8,5,6,7]
tf.reset_default_graph()
with tf.Session() as sess:
cell = tf.contrib.rnn.BasicLSTMCell(1)
cn = tf.placeholder(tf.int32, shape=[None, 9],name="cn")
ut = tf.placeholder(tf.int32, shape=[None, 9],name="ut")
with tf.variable_scope("word_emb",reuse=None):
W = tf.get_variable("word_embed",shape=[10,1])
cn_e = tf.nn.embedding_lookup(W, cn)
ut_e = tf.nn.embedding_lookup(W, ut)
cn_e = tf.unstack(cn_e,9,1)
ut_e = tf.unstack(ut_e,9,1)
#print cn_e.get_shape().as_list()
with tf.variable_scope("encoding_1"):
c_out,c_state = tf.contrib.rnn.static_rnn(cell,cn_e,dtype=tf.float32)
with tf.variable_scope("encoding_2"):
u_out,u_state = tf.contrib.rnn.static_rnn(cell,ut_e,dtype=tf.float32)
print c_state[0].eval()
print u_state[0].eval()
comb_out,comb_state = tf.contrib.rnn.static_rnn(cell,tf.concat(c_state,u_state))
init_op = tf.global_variables_initializer()
sess.run(init_op)
sess.run(comb_out,feed_dict={
cn:np.random.randint(0, 25, size=[1, 9])
,ut:np.random.randint(0, 25, size=[1, 9])
})

但是,我面临此错误:

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'cn' with dtype int32

我不明白,因为我在feed_dict喂 cn .另一个后续问题,这是连接RNN状态的正确方法吗?

问题出在这两行:

print c_state[0].eval()
print u_state[0].eval()

由于c_state和u_state都依赖于占位符,因此应为它们提供值。

最新更新