class_docstr: Translation model that considers how a word can be aligned to
  multiple words in another language
  
  >>> bitext = []
  >>> bitext.append(AlignedSent(['klein', 'ist', 'das', 'haus'], ['the', 'house', 'is', 'small']))
  >>> bitext.append(AlignedSent(['das', 'haus', 'war', 'ja', 'groß'], ['the', 'house', 'was', 'big']))
  >>> bitext.append(AlignedSent(['das', 'buch', 'ist', 'ja', 'klein'], ['the', 'book', 'is', 'small']))
  >>> bitext.append(AlignedSent(['ein', 'haus', 'ist', 'klein'], ['a', 'house', 'is', 'small']))
  >>> bitext.append(AlignedSent(['das', 'haus'], ['the', 'house']))
  >>> bitext.append(AlignedSent(['das', 'buch'], ['the', 'book']))
  >>> bitext.append(AlignedSent(['ein', 'buch'], ['a', 'book']))
  >>> bitext.append(AlignedSent(['ich', 'fasse', 'das', 'buch', 'zusammen'], ['i', 'summarize', 'the', 'book']))
  >>> bitext.append(AlignedSent(['fasse', 'zusammen'], ['summarize']))
  
  >>> ibm3 = IBMModel3(bitext, 5)
  
  >>> print(round(ibm3.translation_table['buch']['book'], 3))
  1.0
  >>> print(round(ibm3.translation_table['das']['book'], 3))
  0.0
  >>> print(round(ibm3.translation_table['ja'][None], 3))
  1.0
  
  >>> print(round(ibm3.distortion_table[1][1][2][2], 3))
  1.0
  >>> print(round(ibm3.distortion_table[1][2][2][2], 3))
  0.0
  >>> print(round(ibm3.distortion_table[2][2][4][5], 3))
  0.75
  
  >>> print(round(ibm3.fertility_table[2]['summarize'], 3))
  1.0
  >>> print(round(ibm3.fertility_table[1]['book'], 3))
  1.0
  
  >>> print(round(ibm3.p1, 3))
  0.054
  
  >>> 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, None), (4, 3)])
class_docstr_tok: ["Translation","model","that","considers","how","a","word","can","be","aligned","to","multiple","words","in","another","language",">",">",">","bitext","=","[","]",">",">",">","bitext.append","(","AlignedSent","(","[","'klein","'",",","'ist","'",",","'das","'",",","'haus","'","]",",","[","'the","'",",","'house","'",",","'is","'",",","'small","'","]",")",")",">",">",">","bitext.append","(","AlignedSent","(","[","'das","'",",","'haus","'",",","'war","'",",","'ja","'",",","'gro\u00df","'","]",",","[","'the","'",",","'house","'",",","'was","'",",","'big","'","]",")",")",">",">",">","bitext.append","(","AlignedSent","(","[","'das","'",",","'buch","'",",","'ist","'",",","'ja","'",",","'klein","'","]",",","[","'the","'",",","'book","'",",","'is","'",",","'small","'","]",")",")",">",">",">","bitext.append","(","AlignedSent","(","[","'ein","'",",","'haus","'",",","'ist","'",",","'klein","'","]",",","[","'","a","'",",","'house","'",",","'is","'",",","'small","'","]",")",")",">",">",">","bitext.append","(","AlignedSent","(","[","'das","'",",","'haus","'","]",",","[","'the","'",",","'house","'","]",")",")",">",">",">","bitext.append","(","AlignedSent","(","[","'das","'",",","'buch","'","]",",","[","'the","'",",","'book","'","]",")",")",">",">",">","bitext.append","(","AlignedSent","(","[","'ein","'",",","'buch","'","]",",","[","'","a","'",",","'book","'","]",")",")",">",">",">","bitext.append","(","AlignedSent","(","[","'ich","'",",","'fasse","'",",","'das","'",",","'buch","'",",","'zusammen","'","]",",","[","'","i","'",",","'summarize","'",",","'the","'",",","'book","'","]",")",")",">",">",">","bitext.append","(","AlignedSent","(","[","'fasse","'",",","'zusammen","'","]",",","[","'summarize","'","]",")",")",">",">",">","ibm3","=","IBMModel3","(","bitext",",","5",")",">",">",">","print","(","round","(","ibm3.translation_table","[","'buch","'","]","[","'book","'","]",",","3",")",")","1.0",">",">",">","print","(","round","(","ibm3.translation_table","[","'das","'","]","[","'book","'","]",",","3",")",")","0.0",">",">",">","print","(","round","(","ibm3.translation_table","[","'ja","'","]","[","None","]",",","3",")",")","1.0",">",">",">","print","(","round","(","ibm3.distortion_table","[","1","]","[","1","]","[","2","]","[","2","]",",","3",")",")","1.0",">",">",">","print","(","round","(","ibm3.distortion_table","[","1","]","[","2","]","[","2","]","[","2","]",",","3",")",")","0.0",">",">",">","print","(","round","(","ibm3.distortion_table","[","2","]","[","2","]","[","4","]","[","5","]",",","3",")",")","0.75",">",">",">","print","(","round","(","ibm3.fertility_table","[","2","]","[","'summarize","'","]",",","3",")",")","1.0",">",">",">","print","(","round","(","ibm3.fertility_table","[","1","]","[","'book","'","]",",","3",")",")","1.0",">",">",">","print","(","round","(","ibm3.p1",",","3",")",")","0.054",">",">",">","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",",","None",")",",","(","4",",","3",")","]",")"]
code: def train(self, parallel_corpus):
      counts = Model3Counts()
      for aligned_sentence in parallel_corpus:
          l = len(aligned_sentence.mots)
          m = len(aligned_sentence.words)
  
          # Sample the alignment space
          sampled_alignments, best_alignment = self.sample(
              aligned_sentence
          )
          # Record the most probable alignment
          aligned_sentence.alignment = Alignment(
              best_alignment.zero_indexed_alignment()
          )
  
          # E step (a): Compute normalization factors to weigh counts
          total_count = self.prob_of_alignments(sampled_alignments)
  
          # E step (b): Collect counts
          for alignment_info in sampled_alignments:
              count = self.prob_t_a_given_s(alignment_info)
              normalized_count = count / total_count
  
              for j in range(1, m + 1):
                  counts.update_lexical_translation(
                      normalized_count, alignment_info, j
                  )
                  counts.update_distortion(
                      normalized_count, alignment_info, j, l, m
                  )
  
              counts.update_null_generation(
                  normalized_count, alignment_info
              )
              counts.update_fertility(normalized_count, alignment_info)
  
      # M step: Update probabilities with maximum likelihood estimates
      # If any probability is less than MIN_PROB, clamp it to MIN_PROB
      existing_alignment_table = self.alignment_table
      self.reset_probabilities()
      self.alignment_table = existing_alignment_table  # don't retrain
  
      self.maximize_lexical_translation_probabilities(counts)
      self.maximize_distortion_probabilities(counts)
      self.maximize_fertility_probabilities(counts)
      self.maximize_null_generation_probabilities(counts)
  
file_path: nltk/nltk/translate/ibm3.py
imports: import warnings
  from collections import defaultdict
  from math import factorial
  from nltk.translate import AlignedSent, Alignment, IBMModel, IBMModel2
  from nltk.translate.ibm_model import Counts
label_desc: Use image node_id 4 for calling the IBMModel3 obj's underlying member method code with example usage: obj.train(parallel_corpus) without return types