class_docstr: Base class for criteria with need to run beam search.
class_docstr_tok: ["Base","class","for","criteria","with","need","to","run","beam","search","."]
docstr: Get lazy singleton translator instance.
docstr_tok: ["Get","lazy","singleton","translator","instance","."]
code: def get_translator(self, model):
      """Get lazy singleton translator instance."""
      if self.translator is None:
          args_clone = copy.copy(self.args)
          if self.args.loss_beam:  # Override beam size if necessary
              args_clone.beam = self.args.loss_beam
          self.translator = generate.build_sequence_generator(
              args_clone, [model]
          )
      return self.translator
  
imports: import copy
  import math
  import torch
  from fairseq import utils
  from fairseq.criterions import LegacyFairseqCriterion, register_criterion
  from fairseq.scoring import bleu
  from pytorch_translate import generate
label_desc: Use image node_id 2 for calling the BaseSequenceLossCriterion obj's underlying member method code with example usage: obj.get_translator(model) and returns: self