nltk.translate.IBMModel¶
- class nltk.translate.IBMModel[source]¶
Bases:
object
Abstract base class for all IBM models
- MIN_PROB = 1e-12¶
- set_uniform_probabilities(sentence_aligned_corpus)[source]¶
Initialize probability tables to a uniform distribution
Derived classes should implement this accordingly.
- sample(sentence_pair)[source]¶
Sample the most probable alignments from the entire alignment space
First, determine the best alignment according to IBM Model 2. With this initial alignment, use hill climbing to determine the best alignment according to a higher IBM Model. Add this alignment and its neighbors to the sample set. Repeat this process with other initial alignments obtained by pegging an alignment point.
Hill climbing may be stuck in a local maxima, hence the pegging and trying out of different alignments.
- Parameters
sentence_pair (AlignedSent) – Source and target language sentence pair to generate a sample of alignments from
- Returns
A set of best alignments represented by their
AlignmentInfo
and the best alignment of the set for convenience- Return type
set(AlignmentInfo), AlignmentInfo
- best_model2_alignment(sentence_pair, j_pegged=None, i_pegged=0)[source]¶
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
- Parameters
sentence_pair (AlignedSent) – Source and target language sentence pair to be word-aligned
j_pegged (int) – If specified, the alignment point of j_pegged will be fixed to i_pegged
i_pegged (int) – Alignment point to j_pegged
- hillclimb(alignment_info, j_pegged=None)[source]¶
Starting from the alignment in
alignment_info
, look at neighboring alignments iteratively for the best oneThere is no guarantee that the best alignment in the alignment space will be found, because the algorithm might be stuck in a local maximum.
- Parameters
j_pegged (int) – If specified, the search will be constrained to alignments where
j_pegged
remains unchanged- Returns
The best alignment found from hill climbing
- Return type
- neighboring(alignment_info, j_pegged=None)[source]¶
Determine the neighbors of
alignment_info
, obtained by moving or swapping one alignment point- Parameters
j_pegged (int) – If specified, neighbors that have a different alignment point from j_pegged will not be considered
- Returns
A set neighboring alignments represented by their
AlignmentInfo
- Return type
set(AlignmentInfo)