class_docstr: Abstract base class for all IBM models
class_docstr_tok: ["Abstract","base","class","for","all","IBM","models"]
docstr: Finds the best alignment according to IBM Model 2
  
  Used as a starting point for hill climbing in Models 3 and
  above, because it is easier to compute than the best alignments
  in higher models
  
  :param sentence_pair: Source and target language sentence pair
      to be word-aligned
  :type sentence_pair: AlignedSent
  
  :param j_pegged: If specified, the alignment point of j_pegged
      will be fixed to i_pegged
  :type j_pegged: int
  
  :param i_pegged: Alignment point to j_pegged
  :type i_pegged: int
docstr_tok: ["Finds","the","best","alignment","according","to","IBM","Model","2","Used","as","a","starting","point","for","hill","climbing","in","Models","3","and","above",",","because","it","is","easier","to","compute","than","the","best","alignments","in","higher","models",":","param","sentence_pair",":","Source","and","target","language","sentence","pair","to","be","word-aligned",":","type","sentence_pair",":","AlignedSent",":","param","j_pegged",":","If","specified",",","the","alignment","point","of","j_pegged","will","be","fixed","to","i_pegged",":","type","j_pegged",":","int",":","param","i_pegged",":","Alignment","point","to","j_pegged",":","type","i_pegged",":","int"]
code: def best_model2_alignment(
      self, sentence_pair, j_pegged=None, i_pegged=0
  ):
      """
      Finds the best alignment according to IBM Model 2
  
      Used as a starting point for hill climbing in Models 3 and
      above, because it is easier to compute than the best alignments
      in higher models
  
      :param sentence_pair: Source and target language sentence pair
          to be word-aligned
      :type sentence_pair: AlignedSent
  
      :param j_pegged: If specified, the alignment point of j_pegged
          will be fixed to i_pegged
      :type j_pegged: int
  
      :param i_pegged: Alignment point to j_pegged
      :type i_pegged: int
      """
      src_sentence = [None] + sentence_pair.mots
      trg_sentence = ["UNUSED"] + sentence_pair.words  # 1-indexed
  
      l = len(src_sentence) - 1  # exclude NULL
      m = len(trg_sentence) - 1
  
      alignment = [0] * (m + 1)  # init all alignments to NULL
      cepts = [[] for i in range(l + 1)]  # init all cepts to empty list
  
      for j in range(1, m + 1):
          if j == j_pegged:
              # use the pegged alignment instead of searching for best one
              best_i = i_pegged
          else:
              best_i = 0
              max_alignment_prob = IBMModel.MIN_PROB
              t = trg_sentence[j]
  
              for i in range(0, l + 1):
                  s = src_sentence[i]
                  alignment_prob = (
                      self.translation_table[t][s]
                      * self.alignment_table[i][j][l][m]
                  )
  
                  if alignment_prob >= max_alignment_prob:
                      max_alignment_prob = alignment_prob
                      best_i = i
  
          alignment[j] = best_i
          cepts[best_i].append(j)
  
      return AlignmentInfo(
          tuple(alignment),
          tuple(src_sentence),
          tuple(trg_sentence),
          cepts,
      )
  
imports: from bisect import insort_left
  from collections import defaultdict
  from copy import deepcopy
  from math import ceil
label_desc: Use image node_id 6 for calling the IBMModel obj's underlying member method code with example usage: obj.best_model2_alignment(sentence_pair, j_pegged, i_pegged) and returns: AlignmentInfo