code: def select_top_candidate_per_word(
      source_index,
      target_indices_with_prob,
      counter_per_word,
      max_translation_candidates_per_word,
      translation_candidates,
      translation_candidates_set,
  ):
      translation_candidates_saved = 0
      target_indices_with_prob.sort(key=lambda x: x[1], reverse=True)
      for target_index_with_prob in target_indices_with_prob:
          if (
              counter_per_word[source_index]
              >= max_translation_candidates_per_word
          ):
              # don't save more than max_translation_candidates_per_word
              # translation candidates for any one source token
              break
  
          # update translation candidates matrix at [source index, running counter
          # per source token] to = target index
          translation_candidates[
              source_index, counter_per_word[source_index]
          ] = target_index_with_prob[0]
          translation_candidates_set.update(
              (source_index, target_index_with_prob[0])
          )
          counter_per_word[source_index] += 1
          translation_candidates_saved += 1
      return translation_candidates_saved
  
file_path: translate/pytorch_translate/vocab_reduction.py
imports: import codecs
  import logging
  import numpy
  import torch
  import torch.nn
label_desc: Use image node_id 3 for calling a global function with example usage: select_top_candidate_per_word(source_index, target_indices_with_prob, counter_per_word, max_translation_candidates_per_word, translation_candidates, translation_candidates_set) and returns: translation_candidates_saved