Abstract base class for all IBM models
Method | __init__ |
Undocumented |
Method | best |
Finds the best alignment according to IBM Model 2 |
Method | hillclimb |
Starting from the alignment in alignment_info, look at neighboring alignments iteratively for the best one |
Method | init |
Undocumented |
Method | maximize |
Undocumented |
Method | maximize |
Undocumented |
Method | maximize |
Undocumented |
Method | neighboring |
Determine the neighbors of alignment_info, obtained by moving or swapping one alignment point |
Method | prob |
Undocumented |
Method | prob |
Probability of target sentence and an alignment given the source sentence |
Method | reset |
Undocumented |
Method | sample |
Sample the most probable alignments from the entire alignment space |
Method | set |
Initialize probability tables to a uniform distribution |
Constant | MIN |
Undocumented |
Instance Variable | alignment |
dict[int][int][int][int]: float. Probability(i | j,l,m). Values accessed as alignment_table[i][j][l][m]. Used in model 2 and hill climbing in models 3 and above |
Instance Variable | fertility |
dict[int][str]: float. Probability(fertility | source word). Values accessed as fertility_table[fertility][source_word]. Used in model 3 and higher. |
Instance Variable | p1 |
Probability that a generated word requires another target word that is aligned to NULL. Used in model 3 and higher. |
Instance Variable | src |
set(str): All source language words used in training |
Instance Variable | translation |
dict[str][str]: float. Probability(target word | source word). Values accessed as translation_table[target_word][source_word]. |
Instance Variable | trg |
set(str): All target language words used in training |
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 | Source and target language sentence pair to be word-aligned |
j | If specified, the alignment point of j_pegged will be fixed to i_pegged |
i | Alignment point to j_pegged |
Starting from the alignment in alignment_info, look at neighboring alignments iteratively for the best one
There 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 | |
alignment | Undocumented |
j | If specified, the search will be constrained to alignments where j_pegged remains unchanged |
Returns | |
AlignmentInfo | The best alignment found from hill climbing |
Determine the neighbors of alignment_info, obtained by moving or swapping one alignment point
Parameters | |
alignment | Undocumented |
j | If specified, neighbors that have a different alignment point from j_pegged will not be considered |
Returns | |
set(AlignmentInfo) | A set neighboring alignments represented by their AlignmentInfo |
Probability of target sentence and an alignment given the source sentence
All required information is assumed to be in alignment_info and self.
Derived classes should override this method
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 | Source and target language sentence pair to generate a sample of alignments from |
Returns | |
set(AlignmentInfo), AlignmentInfo | A set of best alignments represented by their AlignmentInfo and the best alignment of the set for convenience |
Initialize probability tables to a uniform distribution
Derived classes should implement this accordingly.
dict[int][int][int][int]: float. Probability(i | j,l,m). Values accessed as alignment_table[i][j][l][m]. Used in model 2 and hill climbing in models 3 and above
dict[int][str]: float. Probability(fertility | source word). Values accessed as fertility_table[fertility][source_word]. Used in model 3 and higher.
Probability that a generated word requires another target word that is aligned to NULL. Used in model 3 and higher.