【问题标题】:Does the TensorFlow embedding_attention_seq2seq method implement a bidirectional RNN Encoder by default?TensorFlow embedding_attention_seq2seq方法是否默认实现了双向RNN Encoder?
【发布时间】:2017-07-15 06:38:35
【问题描述】:

我已将 embedding_attention_seq2seq 模块用于机器翻译任务,如以下指定的教程中所述:

https://www.tensorflow.org/versions/master/tutorials/seq2seq/index.html

在教程中指定模型的seq2seq_model.py 中,我注意到如果在这些行中将use_lstm 设置为false,他们默认使用GRUCell:

# Create the internal multi-layer cell for our RNN.
single_cell = tf.nn.rnn_cell.GRUCell(size)
if use_lstm:
  single_cell = tf.nn.rnn_cell.BasicLSTMCell(size)
cell = single_cell
if num_layers > 1:
  cell = tf.nn.rnn_cell.MultiRNNCell([single_cell] * num_layers)

现在,如果编码器是双向的并且上下文化同时考虑了两个隐藏层参数,那么本教程指定为实现模型的论文here 中描述的注意力机制将更具语义意义。 seq2seq_model 文件没有提到双向组件。

所以我的问题是,embedding_attention_seq2seq 是否默认实现了双向 RNN 编码器?

如果不是,它是否只是简单地采用普通 LSTM 编码器的每个时间步的隐藏层输出,从而将上下文限制为仅在它之前出现的句子中的单词?

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    所以我的问题是,embedding_attention_seq2seq 是否默认实现了双向 RNN 编码器?

    不,它没有实现双向 RNN 编码器。编码器的输出(用于构建注意力状态)在embedding_attention_seq2seq 的前几行中构建:

    # Encoder.
    encoder_cell = rnn_cell.EmbeddingWrapper(
        cell, embedding_classes=num_encoder_symbols,
        embedding_size=embedding_size)
    encoder_outputs, encoder_state = rnn.rnn(
        encoder_cell, encoder_inputs, dtype=dtype)
    

    第一行用嵌入包裹了单元格。第二个在 encoder_inputs 上运行 encoder_cell 转发(tf/python/ops/rnn.py 的第 210-228 行)。

    如果不是,它是否只是简单地采用普通 LSTM 编码器的每个时间步的隐藏层输出,从而将上下文限制为仅在它之前出现的句子中的单词?

    没错。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-13
      • 2020-04-21
      • 1970-01-01
      • 1970-01-01
      • 2018-03-17
      • 2017-11-25
      • 2020-07-03
      • 1970-01-01
      相关资源
      最近更新 更多