class_docstr: Lexical translation model that considers word order
  
  >>> bitext = []
  >>> bitext.append(AlignedSent(['klein', 'ist', 'das', 'haus'], ['the', 'house', 'is', 'small']))
  >>> bitext.append(AlignedSent(['das', 'haus', 'ist', 'ja', 'groß'], ['the', 'house', 'is', 'big']))
  >>> bitext.append(AlignedSent(['das', 'buch', 'ist', 'ja', 'klein'], ['the', 'book', 'is', 'small']))
  >>> bitext.append(AlignedSent(['das', 'haus'], ['the', 'house']))
  >>> bitext.append(AlignedSent(['das', 'buch'], ['the', 'book']))
  >>> bitext.append(AlignedSent(['ein', 'buch'], ['a', 'book']))
  
  >>> ibm2 = IBMModel2(bitext, 5)
  
  >>> print(round(ibm2.translation_table['buch']['book'], 3))
  1.0
  >>> print(round(ibm2.translation_table['das']['book'], 3))
  0.0
  >>> print(round(ibm2.translation_table['buch'][None], 3))
  0.0
  >>> print(round(ibm2.translation_table['ja'][None], 3))
  0.0
  
  >>> print(round(ibm2.alignment_table[1][1][2][2], 3))
  0.939
  >>> print(round(ibm2.alignment_table[1][2][2][2], 3))
  0.0
  >>> print(round(ibm2.alignment_table[2][2][4][5], 3))
  1.0
  
  >>> test_sentence = bitext[2]
  >>> test_sentence.words
  ['das', 'buch', 'ist', 'ja', 'klein']
  >>> test_sentence.mots
  ['the', 'book', 'is', 'small']
  >>> test_sentence.alignment
  Alignment([(0, 0), (1, 1), (2, 2), (3, 2), (4, 3)])
class_docstr_tok: ["Lexical","translation","model","that","considers","word","order",">",">",">","bitext","=","[","]",">",">",">","bitext.append","(","AlignedSent","(","[","'klein","'",",","'ist","'",",","'das","'",",","'haus","'","]",",","[","'the","'",",","'house","'",",","'is","'",",","'small","'","]",")",")",">",">",">","bitext.append","(","AlignedSent","(","[","'das","'",",","'haus","'",",","'ist","'",",","'ja","'",",","'gro\u00df","'","]",",","[","'the","'",",","'house","'",",","'is","'",",","'big","'","]",")",")",">",">",">","bitext.append","(","AlignedSent","(","[","'das","'",",","'buch","'",",","'ist","'",",","'ja","'",",","'klein","'","]",",","[","'the","'",",","'book","'",",","'is","'",",","'small","'","]",")",")",">",">",">","bitext.append","(","AlignedSent","(","[","'das","'",",","'haus","'","]",",","[","'the","'",",","'house","'","]",")",")",">",">",">","bitext.append","(","AlignedSent","(","[","'das","'",",","'buch","'","]",",","[","'the","'",",","'book","'","]",")",")",">",">",">","bitext.append","(","AlignedSent","(","[","'ein","'",",","'buch","'","]",",","[","'","a","'",",","'book","'","]",")",")",">",">",">","ibm2","=","IBMModel2","(","bitext",",","5",")",">",">",">","print","(","round","(","ibm2.translation_table","[","'buch","'","]","[","'book","'","]",",","3",")",")","1.0",">",">",">","print","(","round","(","ibm2.translation_table","[","'das","'","]","[","'book","'","]",",","3",")",")","0.0",">",">",">","print","(","round","(","ibm2.translation_table","[","'buch","'","]","[","None","]",",","3",")",")","0.0",">",">",">","print","(","round","(","ibm2.translation_table","[","'ja","'","]","[","None","]",",","3",")",")","0.0",">",">",">","print","(","round","(","ibm2.alignment_table","[","1","]","[","1","]","[","2","]","[","2","]",",","3",")",")","0.939",">",">",">","print","(","round","(","ibm2.alignment_table","[","1","]","[","2","]","[","2","]","[","2","]",",","3",")",")","0.0",">",">",">","print","(","round","(","ibm2.alignment_table","[","2","]","[","2","]","[","4","]","[","5","]",",","3",")",")","1.0",">",">",">","test_sentence","=","bitext","[","2","]",">",">",">","test_sentence.words","[","'das","'",",","'buch","'",",","'ist","'",",","'ja","'",",","'klein","'","]",">",">",">","test_sentence.mots","[","'the","'",",","'book","'",",","'is","'",",","'small","'","]",">",">",">","test_sentence.alignment","Alignment","(","[","(","0",",","0",")",",","(","1",",","1",")",",","(","2",",","2",")",",","(","3",",","2",")",",","(","4",",","3",")","]",")"]
docstr: Determines the best word alignment for one sentence pair from
  the corpus that the model was trained on.
  
  The best alignment will be set in ``sentence_pair`` when the
  method returns. In contrast with the internal implementation of
  IBM models, the word indices in the ``Alignment`` are zero-
  indexed, not one-indexed.
  
  :param sentence_pair: A sentence in the source language and its
      counterpart sentence in the target language
  :type sentence_pair: AlignedSent
docstr_tok: ["Determines","the","best","word","alignment","for","one","sentence","pair","from","the","corpus","that","the","model","was","trained","on",".","The","best","alignment","will","be","set","in","``","sentence_pair","``","when","the","method","returns",".","In","contrast","with","the","internal","implementation","of","IBM","models",",","the","word","indices","in","the","``","Alignment","``","are","zero-","indexed",",","not","one-indexed",".",":","param","sentence_pair",":","A","sentence","in","the","source","language","and","its","counterpart","sentence","in","the","target","language",":","type","sentence_pair",":","AlignedSent"]
code: def align(self, sentence_pair):
      """
      Determines the best word alignment for one sentence pair from
      the corpus that the model was trained on.
  
      The best alignment will be set in ``sentence_pair`` when the
      method returns. In contrast with the internal implementation of
      IBM models, the word indices in the ``Alignment`` are zero-
      indexed, not one-indexed.
  
      :param sentence_pair: A sentence in the source language and its
          counterpart sentence in the target language
      :type sentence_pair: AlignedSent
      """
      best_alignment = []
  
      l = len(sentence_pair.mots)
      m = len(sentence_pair.words)
  
      for j, trg_word in enumerate(sentence_pair.words):
          # Initialize trg_word to align with the NULL token
          best_prob = (
              self.translation_table[trg_word][None]
              * self.alignment_table[0][j + 1][l][m]
          )
          best_prob = max(best_prob, IBMModel.MIN_PROB)
          best_alignment_point = None
          for i, src_word in enumerate(sentence_pair.mots):
              align_prob = (
                  self.translation_table[trg_word][src_word]
                  * self.alignment_table[i + 1][j + 1][l][m]
              )
              if align_prob >= best_prob:
                  best_prob = align_prob
                  best_alignment_point = i
  
          best_alignment.append((j, best_alignment_point))
  
      sentence_pair.alignment = Alignment(best_alignment)
  
imports: import warnings
  from collections import defaultdict
  from nltk.translate import AlignedSent, Alignment, IBMModel, IBMModel1
  from nltk.translate.ibm_model import Counts
label_desc: Use image node_id 9 for calling the IBMModel2 obj's underlying member method code with example usage: obj.align(sentence_pair) without return types