我刚开始使用tensorflow。我正在按照Thang Luong,Eugene Brevdo,Rui Zhao给出的神经机器翻译教程
https://www.tensorflow.org/tutorials/seq2seq
我想将该模型用作自动编码器,但我想知道如何在推理时获得编码器隐藏状态?
非常感谢任何帮助。
答案 0 :(得分:0)
如果您使用的是dynamic encoder architecture defined in the NMT tutorial:
\ref
然后执行# 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)
将返回 final 节点的编码器隐藏状态。如果要从所有所有个节点获取状态,我将引用此Stack Overflow question。