code: def collapse_copy_scores(scores, batch, tgt_vocab, batch_dim=1):
      """
      Given scores from an expanded dictionary
      corresponeding to a batch, sums together copies,
      with a dictionary word when it is ambiguous.
      """
      offset = len(tgt_vocab)
      for b in range(scores.size(batch_dim)):
          blank = []
          fill = []
  
          src_vocab = batch["src_ex_vocab"][b]
  
          for i in range(1, len(src_vocab)):
              sw = src_vocab.ids_to_tokens[i]
              ti = tgt_vocab[sw]
              if ti != 0:
                  blank.append(offset + i)
                  fill.append(ti)
          if blank:
              blank = torch.Tensor(blank).to(torch.int64)
              fill = torch.Tensor(fill).to(torch.int64)
              score = scores[:, b] if batch_dim == 1 else scores[b]
              score.index_add_(1, fill, score.index_select(1, blank))
              score.index_fill_(1, blank, 1e-10)
      return scores
  
file_path: OpenNMT-py/onmt/modules/copy_generator.py
imports: import torch
  import torch.nn
label_desc: Use image node_id 1 for calling a global function with example usage: collapse_copy_scores(scores, batch, tgt_vocab, batch_dim) and returns: scores