Warning: This project is deprecated. TensorFlow Addons has stopped development, The project will only be providing minimal maintenance releases until May 2024. See the full announcement here or on github.

tfa.seq2seq.AttentionWrapperState

View source on GitHub

State of a tfa.seq2seq.AttentionWrapper.

tfa.seq2seq.AttentionWrapperState(
 cell_state, attention, alignments, alignment_history, attention_state
)

Attributes

cell_state The state of the wrapped RNN cell at the previous time step.
attention The attention emitted at the previous time step.
alignments A single or tuple of Tensor(s) containing the alignments emitted at the previous time step for each attention mechanism.
alignment_history (if enabled) a single or tuple of TensorArray(s) containing alignment matrices from all time steps for each attention mechanism. Call stack() on each to convert to a Tensor.
attention_state A single or tuple of nested objects containing attention mechanism state for each attention mechanism. The objects may contain Tensors or TensorArrays.

Methods

clone

View source

clone(
 **kwargs
)

Clone this object, overriding components provided by kwargs.

The new state fields' shape must match original state fields' shape. This will be validated, and original fields' shape will be propagated to new fields.

Example:

batch_size = 1
memory = tf.random.normal(shape=[batch_size, 3, 100])
encoder_state = [tf.zeros((batch_size, 100)), tf.zeros((batch_size, 100))]
attention_mechanism = tfa.seq2seq.LuongAttention(100, memory=memory, memory_sequence_length=[3] * batch_size)
attention_cell = tfa.seq2seq.AttentionWrapper(tf.keras.layers.LSTMCell(100), attention_mechanism, attention_layer_size=10)
decoder_initial_state = attention_cell.get_initial_state(batch_size=batch_size, dtype=tf.float32)
decoder_initial_state = decoder_initial_state.clone(cell_state=encoder_state)

Args
**kwargs Any properties of the state object to replace in the returned AttentionWrapperState.

Returns
A new AttentionWrapperState whose properties are the same as this one, except any overridden properties as provided in kwargs.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2023年05月25日 UTC.