アタックメカニズムを使用する多層のダイナミックRNNベースのデコーダを作成したいと考えています。 self._create_lstm_cell
は次のように定義されてAttentionMechanismをMultiRNNCellとdynamic_decodeで使用する方法は?
attention_wrapper = AttentionWrapper(cell=self._create_lstm_cell(DECODER_SIZE),
attention_mechanism=attention_mechanism,
output_attention=False,
alignment_history=True,
attention_layer_size=ATTENTION_LAYER_SIZE)
は、次のとおりです:
attention_mechanism = BahdanauAttention(num_units=ATTENTION_UNITS,
memory=encoder_outputs,
normalize=True)
は、その後、私は注意機構をLSTMセルをラップするAttentionWrapper
を使用します。これを行うには、私が最初に注目メカニズムを作成します
@staticmethod
def _create_lstm_cell(cell_size):
return BasicLSTMCell(cell_size)
次に、私はMultiRNNCell
を作成し、初期状態を作成し、TrainingHelper
などを作成しています)
attention_zero = attention_wrapper.zero_state(batch_size=tf.flags.FLAGS.batch_size, dtype=tf.float32)
# define initial state
initial_state = attention_zero.clone(cell_state=encoder_final_states[0])
training_helper = TrainingHelper(inputs=self.y, # feed in ground truth
sequence_length=self.y_lengths) # feed in sequence lengths
layered_cell = MultiRNNCell(
[attention_wrapper] + [ResidualWrapper(self._create_lstm_cell(cell_size=DECODER_SIZE))
for _ in range(NUMBER_OF_DECODER_LAYERS - 1)])
decoder = BasicDecoder(cell=layered_cell,
helper=training_helper,
initial_state=initial_state)
decoder_outputs, decoder_final_state, decoder_final_sequence_lengths = dynamic_decode(decoder=decoder,
maximum_iterations=tf.flags.FLAGS.max_number_of_scans // 12,
impute_finished=True)
しかし、私は次のエラーを受け取ります:AttributeError: 'LSTMStateTuple' object has no attribute 'attention'
。
MultiRNNCellダイナミックデコーダにアテンション機構を追加する正しい方法は何ですか?