code: def _unk_replace(
      source_tokens, predicted_tokens, attention_scores, mapping=None
  ):
      """Replaces UNK tokens with tokens from the source or a
      provided mapping based on the attention scores.
  
      Args:
        source_tokens: A numpy array of strings.
        predicted_tokens: A numpy array of strings.
        attention_scores: A numeric numpy array
          of shape `[prediction_length, source_length]` that contains
          the attention scores.
        mapping: If not provided, an UNK token is replaced with the
          source token that has the highest attention score. If provided
          the token is insead replaced with `mapping[chosen_source_token]`.
  
      Returns:
        A new `predicted_tokens` array.
      """
      result = []
      for token, scores in zip(predicted_tokens, attention_scores):
          if token == "UNK":
              max_score_index = np.argmax(scores)
              chosen_source_token = source_tokens[max_score_index]
              new_target = chosen_source_token
              if mapping is not None and chosen_source_token in mapping:
                  new_target = mapping[chosen_source_token]
              result.append(new_target)
          else:
              result.append(token)
      return np.array(result)
  
file_path: seq2seq/seq2seq/tasks/decode_text.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import functools
  from pydoc import locate
  import numpy
  import tensorflow
  from tensorflow import gfile
  from seq2seq.tasks.inference_task import InferenceTask, unbatch_dict
label_desc: Use image node_id 3 for calling a global function with example usage: _unk_replace(source_tokens, predicted_tokens, attention_scores, mapping) and returns: np