opennmt/models/sequence_to_sequence.py
def replace_unknown_target(
    target_tokens, source_tokens, attention, unknown_token=constants.UNKNOWN_TOKEN
):
    """Replaces all target unknown tokens by the source token with the highest
    attention.

    Args:
      target_tokens: A string ``tf.Tensor`` of shape :math:`[B, T_t]`.
      source_tokens: A string ``tf.Tensor`` of shape :math:`[B, T_s]`.
      attention: The attention vector of shape :math:`[B, T_t, T_s]`.
      unknown_token: The target token to replace.

    Returns:
      A string ``tf.Tensor`` with the same shape and type as :obj:`target_tokens`
      but will all instances of :obj:`unknown_token` replaced by the aligned source
      token.
    """
    aligned_source_tokens = align_tokens_from_attention(source_tokens, attention)
    return tf.where(
        tf.equal(target_tokens, unknown_token), x=aligned_source_tokens, y=target_tokens
    )
Replaces all target unknown tokens by the source token with the highest
    attention.

    Args:
      target_tokens: A string ``tf.Tensor`` of shape :math:`[B, T_t]`.
      source_tokens: A string ``tf.Tensor`` of shape :math:`[B, T_s]`.
      attention: The attention vector of shape :math:`[B, T_t, T_s]`.
      unknown_token: The target token to replace.

    Returns:
      A string ``tf.Tensor`` with the same shape and type as :obj:`target_tokens`
      but will all instances of :obj:`unknown_token` replaced by the aligned source
      token.
    
Replaces all target unknown tokens by the source token with the highest
attention.
Replaces all target unknown tokens by the source token with the highest attention .
def replace_unknown_target(
    target_tokens, source_tokens, attention, unknown_token=constants.UNKNOWN_TOKEN
):
    aligned_source_tokens = align_tokens_from_attention(source_tokens, attention)
    return tf.where(
        tf.equal(target_tokens, unknown_token), x=aligned_source_tokens, y=target_tokens
    )
def replace_unknown_target ( target_tokens , source_tokens , attention , unknown_token = constants . UNKNOWN_TOKEN ) : aligned_source_tokens = align_tokens_from_attention ( source_tokens , attention ) return tf . where ( tf . equal ( target_tokens , unknown_token ) , x = aligned_source_tokens , y = target_tokens )
Replaces all target unknown tokens by the source token with the highest
attention.
Replaces all target unknown tokens by the source token with the highest attention .
"""Replaces all target unknown tokens by the source token with the highest
    attention.

    Args:
      target_tokens: A string ``tf.Tensor`` of shape :math:`[B, T_t]`.
      source_tokens: A string ``tf.Tensor`` of shape :math:`[B, T_s]`.
      attention: The attention vector of shape :math:`[B, T_t, T_s]`.
      unknown_token: The target token to replace.

    Returns:
      A string ``tf.Tensor`` with the same shape and type as :obj:`target_tokens`
      but will all instances of :obj:`unknown_token` replaced by the aligned source
      token.
    """
A string ``tf.Tensor`` with the same shape and type as :obj:`target_tokens`
but will all instances of :obj:`unknown_token` replaced by the aligned source
token.
A string ` ` tf . Tensor ` ` with the same shape and type as : obj : ` target_tokens ` but will all instances of : obj : ` unknown_token ` replaced by the aligned source token .
target_tokens
A string ``tf.Tensor`` of shape :math:`[B, T_t]`.
A string ` ` tf . Tensor ` ` of shape : math : ` [ B T_t ] ` .
source_tokens
A string ``tf.Tensor`` of shape :math:`[B, T_s]`.
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 ] ` .
unknown_token
The target token to replace.
The target token to replace .