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 loss between 2 partial alignment matrix.
docstr_tok: ["Compute","loss","between","2","partial","alignment","matrix","."]
code: def _compute_alignement_loss(self, align_head, ref_align):
      """Compute loss between 2 partial alignment matrix."""
      # align_head contains value in [0, 1) presenting attn prob,
      # 0 was resulted by the context attention src_pad_mask
      # So, the correspand position in ref_align should also be 0
      # Therefore, clip align_head to > 1e-18 should be bias free.
      align_loss = (
          -align_head.clamp(min=1e-18).log().mul(ref_align).sum()
      )
      align_loss *= self.lambda_align
      return align_loss
  
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 5 for calling the LossCompute obj's underlying member method code with example usage: obj._compute_alignement_loss(align_head, ref_align) and returns: align_loss