class_docstr: Build a word-based translation from the batch output
  of translator and the underlying dictionaries.
  
  Replacement based on "Addressing the Rare Word
  Problem in Neural Machine Translation" :cite:`Luong2015b`
  
  Args:
     data ():
     vocabs ():
     n_best (int): number of translations produced
     replace_unk (bool): replace unknown words using attention
code: def from_batch(self, translation_batch):
      batch = translation_batch["batch"]
      if "src_ex_vocab" in batch.keys():
          dyn_voc_batch = batch["src_ex_vocab"]
      else:
          dyn_voc_batch = None
      assert len(translation_batch["gold_score"]) == len(
          translation_batch["predictions"]
      )
      batch_size = len(batch["srclen"])
  
      preds, pred_score, attn, align, gold_score, ind = (
          translation_batch["predictions"],
          translation_batch["scores"],
          translation_batch["attention"],
          translation_batch["alignment"],
          translation_batch["gold_score"],
          batch["ind_in_bucket"],
      )
  
      if not any(align):  # when align is a empty nested list
          align = [None] * batch_size
  
      src = batch["src"][:, :, 0]
      srclen = batch["srclen"][:]
      if "tgt" in batch.keys():
          tgt = batch["tgt"][:, :, 0]
      else:
          tgt = None
  
      translations = []
      voc_tgt = self.vocabs["tgt"].ids_to_tokens
  
      # These comp lists are costy but less than for loops
      for b in range(batch_size):
          if dyn_voc_batch is not None:
              dyn_voc = dyn_voc_batch[b]
          else:
              dyn_voc = None
          pred_sents = [
              self._build_target_tokens(
                  src[b, :] if src is not None else None,
                  srclen[b],
                  preds[b][n],
                  align[b][n] if align[b] is not None else attn[b][n],
                  voc_tgt,
                  dyn_voc,
              )
              for n in range(self.n_best)
          ]
  
          gold_sent = None
          if tgt is not None:
              gold_sent = self._build_target_tokens(
                  src[b, :] if src is not None else None,
                  srclen[b],
                  tgt[b, 1:] if tgt is not None else None,
                  None,
                  voc_tgt,
                  dyn_voc,
              )
  
          translation = Translation(
              src[b, :] if src is not None else None,
              srclen[b],
              pred_sents,
              attn[b],
              pred_score[b],
              gold_sent,
              gold_score[b],
              align[b],
              ind[b],
          )
          translations.append(translation)
  
      return translations
  
file_path: OpenNMT-py/onmt/translate/translation.py
imports: import os
  from onmt.constants import DefaultTokens
  from onmt.utils.alignment import build_align_pharaoh
label_desc: Use image node_id 3 for calling the TranslationBuilder obj's underlying member method code with example usage: obj.from_batch(translation_batch) and returns: translations