class_docstr: Returns the Length and Coverage Penalty function for Beam Search.
  
  Args:
      length_pen (str): option name of length pen
      cov_pen (str): option name of cov pen
  
  Attributes:
      has_cov_pen (bool): Whether coverage penalty is None (applying it
          is a no-op). Note that the converse isn't true. Setting beta
          to 0 should force coverage length to be a no-op.
      has_len_pen (bool): Whether length penalty is None (applying it
          is a no-op). Note that the converse isn't true. Setting alpha
          to 1 should force length penalty to be a no-op.
      coverage_penalty (callable[[FloatTensor, float], FloatTensor]):
          Calculates the coverage penalty.
      length_penalty (callable[[int, float], float]): Calculates
          the length penalty.
class_docstr_tok: ["Returns","the","Length","and","Coverage","Penalty","function","for","Beam","Search",".","Args",":","length_pen","(","str",")",":","option","name","of","length","pen","cov_pen","(","str",")",":","option","name","of","cov","pen","Attributes",":","has_cov_pen","(","bool",")",":","Whether","coverage","penalty","is","None","(","applying","it","is","a","no-op",")",".","Note","that","the","converse","is","n't","true",".","Setting","beta","to","0","should","force","coverage","length","to","be","a","no-op",".","has_len_pen","(","bool",")",":","Whether","length","penalty","is","None","(","applying","it","is","a","no-op",")",".","Note","that","the","converse","is","n't","true",".","Setting","alpha","to","1","should","force","length","penalty","to","be","a","no-op",".","coverage_penalty","(","callable","[","[","FloatTensor",",","float","]",",","FloatTensor","]",")",":","Calculates","the","coverage","penalty",".","length_penalty","(","callable","[","[","int",",","float","]",",","float","]",")",":","Calculates","the","length","penalty","."]
docstr: GNMT coverage re-ranking score.
  
  See "Google's Neural Machine Translation System" :cite:`wu2016google`.
  ``cov`` is expected to be sized ``(*, seq_len)``, where ``*`` is
  probably ``batch_size x beam_size`` but could be several
  dimensions like ``(batch_size, beam_size)``. If ``cov`` is attention,
  then the ``seq_len`` axis probably sums to (almost) 1.
docstr_tok: ["GNMT","coverage","re-ranking","score",".","See","``","Google","'s","Neural","Machine","Translation","System","''",":","cite",":","`","wu2016google","`",".","``","cov","``","is","expected","to","be","sized","``","(","*",",","seq_len",")","``",",","where","``","*","``","is","probably","``","batch_size","x","beam_size","``","but","could","be","several","dimensions","like","``","(","batch_size",",","beam_size",")","``",".","If","``","cov","``","is","attention",",","then","the","``","seq_len","``","axis","probably","sums","to","(","almost",")","1","."]
code: def coverage_wu(self, cov, beta=0.0):
      """GNMT coverage re-ranking score.
  
      See "Google's Neural Machine Translation System" :cite:`wu2016google`.
      ``cov`` is expected to be sized ``(*, seq_len)``, where ``*`` is
      probably ``batch_size x beam_size`` but could be several
      dimensions like ``(batch_size, beam_size)``. If ``cov`` is attention,
      then the ``seq_len`` axis probably sums to (almost) 1.
      """
  
      penalty = -torch.min(cov, cov.clone().fill_(1.0)).log().sum(-1)
      return beta * penalty
  
file_path: OpenNMT-py/onmt/translate/penalties.py
imports: import torch
label_desc: Use image node_id 5 for calling the PenaltyBuilder obj's underlying member method code with example usage: obj.coverage_wu(cov, beta) and returns: unknown