opennmt/models/sequence_to_sequence.py
def align_tokens_from_attention(tokens, attention):
    """Returns aligned tokens from the attention.

    Args:
      tokens: The tokens on which the attention is applied as a string
        ``tf.Tensor`` of shape :math:`[B, T_s]`.
      attention: The attention vector of shape :math:`[B, T_t, T_s]`.

    Returns:
      The aligned tokens as a string ``tf.Tensor`` of shape :math:`[B, T_t]`.
    """
    alignment = tf.argmax(attention, axis=-1, output_type=tf.int32)
    return tf.gather(tokens, alignment, axis=1, batch_dims=1)
Returns aligned tokens from the attention.

    Args:
      tokens: The tokens on which the attention is applied as a string
        ``tf.Tensor`` of shape :math:`[B, T_s]`.
      attention: The attention vector of shape :math:`[B, T_t, T_s]`.

    Returns:
      The aligned tokens as a string ``tf.Tensor`` of shape :math:`[B, T_t]`.
    
Returns aligned tokens from the attention.
Returns aligned tokens from the attention .
def align_tokens_from_attention(tokens, attention):
    alignment = tf.argmax(attention, axis=-1, output_type=tf.int32)
    return tf.gather(tokens, alignment, axis=1, batch_dims=1)
def align_tokens_from_attention ( tokens , attention ) : alignment = tf . argmax ( attention , axis = - 1 , output_type = tf . int32 ) return tf . gather ( tokens , alignment , axis = 1 , batch_dims = 1 )
Returns aligned tokens from the attention.
Returns aligned tokens from the attention .
"""Returns aligned tokens from the attention.

    Args:
      tokens: The tokens on which the attention is applied as a string
        ``tf.Tensor`` of shape :math:`[B, T_s]`.
      attention: The attention vector of shape :math:`[B, T_t, T_s]`.

    Returns:
      The aligned tokens as a string ``tf.Tensor`` of shape :math:`[B, T_t]`.
    """
The aligned tokens as a string ``tf.Tensor`` of shape :math:`[B, T_t]`.
The aligned tokens as a string ` ` tf . Tensor ` ` of shape : math : ` [ B T_t ] ` .
tokens
The tokens on which the attention is applied as a string
``tf.Tensor`` of shape :math:`[B, T_s]`.
The tokens on which the attention is applied as a string ` ` tf . Tensor ` ` of shape : math : ` [ B T_s ] ` .
attention
The attention vector of shape :math:`[B, T_t, T_s]`.
The attention vector of shape : math : ` [ B T_t T_s ] ` .