'Train on ``sentence_aligned_corpus`` and create a lexical
translation model, vacancy models, a fertility model, and a
model for generating NULL-aligned words.
Translation direction is from ``AlignedSent.mots`` to
``AlignedSent.words``.
:param sentence_aligned_corpus: Sentence-aligned parallel corpus
:type sentence_aligned_corpus: list(AlignedSent)
:param iterations: Number of iterations to run training algorithm
:type iterations: int
:param source_word_classes: Lookup table that maps a source word
to its word class, the latter represented by an integer id
:type source_word_classes: dict[str]: int
:param target_word_classes: Lookup table that maps a target word
to its word class, the latter represented by an integer id
:type target_word_classes: dict[str]: int
:param probability_tables: Optional. Use this to pass in custom
probability values. If not specified, probabilities will be
set to a uniform distribution, or some other sensible value.
If specified, all the following entries must be present:
``translation_table``, ``alignment_table``,
``fertility_table``, ``p1``, ``head_distortion_table``,
``non_head_distortion_table``, ``head_vacancy_table``,
``non_head_vacancy_table``. See ``IBMModel``, ``IBMModel4``,
and ``IBMModel5`` for the type and purpose of these tables.
:type probability_tables: dict[str]: object'

def __init__(self, sentence_aligned_corpus, iterations, source_word_classes, target_word_classes, probability_tables=None):

    super(IBMModel5, self).__init__(sentence_aligned_corpus)
    self.reset_probabilities()
    self.src_classes = source_word_classes
    self.trg_classes = target_word_classes
    if (probability_tables is None):
        ibm4 = IBMModel4(sentence_aligned_corpus, iterations, source_word_classes, target_word_classes)
        self.translation_table = ibm4.translation_table
        self.alignment_table = ibm4.alignment_table
        self.fertility_table = ibm4.fertility_table
        self.p1 = ibm4.p1
        self.head_distortion_table = ibm4.head_distortion_table
        self.non_head_distortion_table = ibm4.non_head_distortion_table
        self.set_uniform_probabilities(sentence_aligned_corpus)
    else:
        self.translation_table = probability_tables['translation_table']
        self.alignment_table = probability_tables['alignment_table']
        self.fertility_table = probability_tables['fertility_table']
        self.p1 = probability_tables['p1']
        self.head_distortion_table = probability_tables['head_distortion_table']
        self.non_head_distortion_table = probability_tables['non_head_distortion_table']
        self.head_vacancy_table = probability_tables['head_vacancy_table']
        self.non_head_vacancy_table = probability_tables['non_head_vacancy_table']
    for n in range(0, iterations):
        self.train(sentence_aligned_corpus)
