我想知道如何在 tensorflow rnn 中制作解码器,将它的第 i 个输出馈送到第 (i+1) 个输入
我的输入有 20 个序列和 3680 个 dementions,我的输出有 39 个序列和 3680 个 dementions 所有数据都是 0~1 数字
这是我的模型
with tf.variable_scope('encoder'):
enc_input = tf.placeholder(tf.float32,[None, input_sequence_length, input_dim])
enc_cell = tf.contrib.rnn.BasicLSTMCell(num_units = input_sequence_length)
_ , encoder_states = tf.nn.dynamic_rnn(enc_cell, enc_input , dtype=tf.float32)
with tf.variable_scope('decoder'):
dec_input = tf.placeholder(tf.float32,[None, output_sequence_length, output_dim])
dec_output = tf.placeholder(tf.float32,[None, output_sequence_length, output_dim])
dec_cell = tf.contrib.rnn.BasicLSTMCell(num_units = output_sequence_length)
outputs , _ = tf.nn.dynamic_rnn(dec_cell, dec_input,dtype = tf.float32,
initial_state = encoder_states)
我如何制作将先前输出馈送到下一个输入的解码器模型?
附言
我像这样制作我的自我回答代码
with tf.variable_scope('decoder'):
dec_input = tf.placeholder(tf.float32,[None, 1, output_dim])
dec_output = tf.placeholder(tf.float32,[None, output_sequence_length, output_dim])
outputs = []
state = encoder_states
dec_cell = tf.contrib.rnn.BasicLSTMCell(num_units = dec_hidden_size)
for i in range(output_sequence_length):
if i==0:
output , state = tf.nn.dynamic_rnn(dec_cell, dec_input, initial_state = state, dtype = tf.float32)
outputs.append(output)
else:
output , state = tf.nn.dynamic_rnn(dec_cell,
output,
initial_state = state,
dtype = tf.float32)
outputs.append(output)
outputs = tf.reshape(outputs,[-1,output_dim])
outputs = tf.reshape(outputs,[-1,output_sequence_length,output_dim])
我认为这段代码的输出与上面代码的输出不同,但我不确定它是否正常工作。
所以我仍然想知道如何使用tensorflow方法制作具有循环函数((i)输出->(i + 1)输入)的解码器,因为它比上层代码需要更多的内存分配。(在我看来它具有相同的细胞计数)