class_docstr: Class for managing efficient loss computation. Handles
  accumulating multiple loss computations.
  
  Args:
      criterion (:obj:`nn. loss function`) : NLLoss or customed loss
      generator (:obj:`nn.Module`) :
      copy_attn (bool): whether copy attention mechanism is on/off
      lambda_coverage: Hyper-param to apply coverage attention if any
      lambda_align: Hyper-param for alignment loss
      tgt_shift_index (int): 1 for NMT, 0 for LM
      vocab: target vocab (for copy attention score calculation)
           module that maps the output of the decoder to a
           distribution over the target vocabulary.
      lm_generator (:obj:`ctranslate2.Generator`): LM Generator
      lm_prior_lambda (float): weight of LM model in loss
      lm_prior_tau (float): scaler for LM loss
class_docstr_tok: ["Class","for","managing","efficient","loss","computation",".","Handles","accumulating","multiple","loss","computations",".","Args",":","criterion","(",":","obj",":","`","nn",".","loss","function","`",")",":","NLLoss","or","customed","loss","generator","(",":","obj",":","`","nn.Module","`",")",":","copy_attn","(","bool",")",":","whether","copy","attention","mechanism","is","on\/off","lambda_coverage",":","Hyper-param","to","apply","coverage","attention","if","any","lambda_align",":","Hyper-param","for","alignment","loss","tgt_shift_index","(","int",")",":","1","for","NMT",",","0","for","LM","vocab",":","target","vocab","(","for","copy","attention","score","calculation",")","module","that","maps","the","output","of","the","decoder","to","a","distribution","over","the","target","vocabulary",".","lm_generator","(",":","obj",":","`","ctranslate2.Generator","`",")",":","LM","Generator","lm_prior_lambda","(","float",")",":","weight","of","LM","model","in","loss","lm_prior_tau","(","float",")",":","scaler","for","LM","loss"]
docstr: Args:
      loss (int): the loss computed by the loss criterion.
      scores (:obj:`FloatTensor`): a score for each possible output
      target (:obj:`FloatTensor`): true targets
  
  Returns:
      :obj:`onmt.utils.Statistics` : statistics for this batch.
docstr_tok: ["Args",":","loss","(","int",")",":","the","loss","computed","by","the","loss","criterion",".","scores","(",":","obj",":","`","FloatTensor","`",")",":","a","score","for","each","possible","output","target","(",":","obj",":","`","FloatTensor","`",")",":","true","targets","Returns",":",":","obj",":","`","onmt.utils.Statistics","`",":","statistics","for","this","batch","."]
code: def _stats(self, bsz, loss, scores, target):
      """
      Args:
          loss (int): the loss computed by the loss criterion.
          scores (:obj:`FloatTensor`): a score for each possible output
          target (:obj:`FloatTensor`): true targets
  
      Returns:
          :obj:`onmt.utils.Statistics` : statistics for this batch.
      """
      pred = scores.max(1)[1]
      non_padding = target.ne(self.padding_idx)
      num_correct = (
          pred.eq(target).masked_select(non_padding).sum().item()
      )
      num_non_padding = non_padding.sum().item()
      n_batchs = 1 if bsz else 0
      # in the case criterion reduction is None then we need
      # to sum the loss of each sentence in the batch
      return onmt.utils.Statistics(
          loss=loss,
          n_batchs=n_batchs,
          n_sents=bsz,
          n_words=num_non_padding,
          n_correct=num_correct,
      )
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  import onmt
  from onmt.modules.sparse_losses import SparsemaxLoss
  from onmt.modules.sparse_activations import LogSparsemax
  from onmt.constants import ModelTask, DefaultTokens
  from onmt.modules.copy_generator import collapse_copy_scores
  from onmt.model_builder import load_test_model
label_desc: Use image node_id 13 for calling the LossCompute obj's underlying member method code with example usage: obj._stats(bsz, loss, scores, target) and returns: onmt