我正在尝试构建一个具有注意力机制的双向 RNN 用于序列分类。我在理解辅助函数时遇到了一些问题。我已经看到用于训练的那个需要解码器输入,但由于我想要整个序列中的一个标签,我不知道我应该在这里给出什么输入。这是我到目前为止构建的结构:
# Encoder LSTM cells
lstm_fw_cell = rnn.BasicLSTMCell(n_hidden)
lstm_bw_cell = rnn.BasicLSTMCell(n_hidden)
# Bidirectional RNN
outputs, states = tf.nn.bidirectional_dynamic_rnn(lstm_fw_cell,
lstm_bw_cell, inputs=x,
sequence_length=seq_len, dtype=tf.float32)
# Concatenate forward and backward outputs
encoder_outputs = tf.concat(outputs,2)
# Decoder LSTM cell
decoder_cell = rnn.BasicLSTMCell(n_hidden)
# Attention mechanism
attention_mechanism = tf.contrib.seq2seq.LuongAttention(n_hidden, encoder_outputs)
attn_cell = tf.contrib.seq2seq.AttentionWrapper(decoder_cell,
attention_mechanism, attention_size=n_hidden)
name="attention_init")
# Initial attention
attn_zero = attn_cell.zero_state(batch_size=tf.shape(x)[0], dtype=tf.float32)
init_state = attn_zero.clone(cell_state=states[0])
# Helper function
helper = tf.contrib.seq2seq.TrainingHelper(inputs = ???)
# Decoding
my_decoder = tf.contrib.seq2seq.BasicDecoder(cell=attn_cell,
helper=helper,
initial_state=init_state)
decoder_outputs, decoder_states = tf.contrib.seq2seq.dynamic_decode(my_decoder)
我的输入是一个序列 [batch_size,sequence_length,n_features],我的输出是一个包含 N 个可能类 [batch_size,n_classes] 的单个向量。
你知道我在这里遗漏了什么,或者是否可以使用 seq2seq 进行序列分类?