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: Compute the copy attention loss.
  Args:
      batch: the current batch.
      output: the predict output from the model.
      target: the validate target to compare output with.
      align:
      attns: dictionary of attention distributions
        `(tgt_len, batch, src_len)`
  Returns:
      A tuple with the loss and raw scores.
docstr_tok: ["Compute","the","copy","attention","loss",".","Args",":","batch",":","the","current","batch",".","output",":","the","predict","output","from","the","model",".","target",":","the","validate","target","to","compare","output","with",".","align",":","attns",":","dictionary","of","attention","distributions","`","(","tgt_len",",","batch",",","src_len",")","`","Returns",":","A","tuple","with","the","loss","and","raw","scores","."]
code: def _compute_copy_loss(self, batch, output, target, align, attns):
      """Compute the copy attention loss.
      Args:
          batch: the current batch.
          output: the predict output from the model.
          target: the validate target to compare output with.
          align:
          attns: dictionary of attention distributions
            `(tgt_len, batch, src_len)`
      Returns:
          A tuple with the loss and raw scores.
      """
      scores = self.generator(
          self._bottle(output),
          self._bottle(attns["copy"]),
          batch["src_map"],
      )
      loss = self.criterion(scores, align, target).sum()
  
      return loss, scores
  
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 6 for calling the LossCompute obj's underlying member method code with example usage: obj._compute_copy_loss(batch, output, target, align, attns) and returns: loss,  scores