我刚刚开始使用tensorflow。我正在学习Thang,Eugene Brevdo,Rui Zhao提供的神经机器翻译教程
https://www.tensorflow.org/tutorials/seq2seq
我想使用该模型作为自动编码器,但我想知道如何在推断时获得编码器的隐藏状态?
任何帮助都将不胜感激。
发布于 2018-10-30 04:08:35
如果您正在使用dynamic encoder architecture defined in the NMT tutorial
# Build RNN cell
encoder_cell = tf.nn.rnn_cell.BasicLSTMCell(num_units)
# Run Dynamic RNN
# encoder_outputs: [max_time, batch_size, num_units]
# encoder_state: [batch_size, num_units]
encoder_outputs, encoder_state = tf.nn.dynamic_rnn(
encoder_cell, encoder_emb_inp,
sequence_length=source_sequence_length, time_major=True)然后执行sess.run([encoder_state], feed_dict={...})[0]将返回最终节点的编码器隐藏状态。如果你想要所有节点的状态,我会参考这个Stack Overflow question。
https://stackoverflow.com/questions/49740955
复制相似问题