Algorithm Search⌘K

Problemcore

Word alignment

Also called bilingual word alignment.

Find which words of a sentence correspond to which words of its translation, as a set of links between positions.

Word alignment is the problem of finding, for a sentence and its translation, which words of one correspond to which words of the other. The answer is a set of links between word positions. A word can have no link, one link or many links, and the links can cross, because languages order words differently. Word alignments are seldom annotated, so they are usually learned without supervision from a parallel corpus of sentence pairs, with a probabilistic model such as IBM Model 1 or the HMM alignment model trained by expectation-maximization. The links are then used to extract phrase pairs and translation lexicons. How hard it is to find the best alignment depends on the model: it is easy under Models 1 and 2 and the HMM, and NP-hard under IBM Model 3.

In plain words

Take an English sentence and its French translation. Draw a line from each French word to the English word that means the same. Some lines are simple: "maison" goes to "house". Some French words need two English words, some English words have no partner, and the lines cross when the two languages put words in a different order. Word alignment is the task of drawing these lines by computer. Usually no one gives the computer any correct lines. It sees only many pairs of sentences, and it learns that words which often appear in the same pairs are likely to be translations. Then it picks the most probable lines for each pair.

Definition

Input. A source sentence f=f1…fmf = f_1 \ldots f_m and a target sentence e=e1…ele = e_1 \ldots e_l that translate each other, and, for the unsupervised problem, a corpus of such pairs with no links.

Output. A set of links A⊆{1,…,m}×{1,…,l}A \subseteq \{1, \ldots, m\} \times \{1, \ldots, l\}, where (j,i)∈A(j, i) \in A means that fjf_j and eie_i are translations of each other, fully or in part.

Directional form. Most models restrict the output to a function a:{1,…,m}→{0,1,…,l}a : \{1, \ldots, m\} \to \{0, 1, \ldots, l\}. Each source word has exactly one link, to a target word or to the null word e0e_0, which stands for "no target word" (Brown et al. 1993). A target word can still have many links. The links of the function are {(j,aj):aj≥1}\{(j, a_j) : a_j \ge 1\}.

Model form. Given a model p(f,a∣e)p(f, a \mid e), the best (Viterbi) alignment of a pair is

a^=arg⁡max⁡ap(a∣f,e)=arg⁡max⁡ap(f,a∣e).\hat a = \arg\max_a p(a \mid f, e) = \arg\max_a p(f, a \mid e).

The quality of an output is measured against links that people made, for example by the alignment error rate.

Variants

  • Direction. The function form with ff as source is one direction, and the function with ee as source is the other. Each direction can express one-to-many links only on its own side. Symmetrization combines the two into one set of links.
  • One-to-one. Each word has at most one link. With a score for each word pair, this is a maximum weight bipartite matching.
  • Posterior links. Instead of the Viterbi alignment, output every link whose posterior probability p(aj=i∣f,e)p(a_j = i \mid f, e) is above a threshold. The forward-backward algorithm gives these posteriors under the HMM model.
  • Supervised alignment. A small set of pairs with gold links is used to train or tune a discriminative aligner.
  • Soft alignment. A neural translation model with attention computes a weight for each pair of positions instead of discrete links.

Examples

  • Monotone. For "das Haus ist klein" and "the house is small", each word links to the word at the same position: A={(1,1),(2,2),(3,3),(4,4)}A = \{(1,1), (2,2), (3,3), (4,4)\}.
  • Reordering. For "klein ist das Haus" (source) and "the house is small" (target), A={(1,4),(2,3),(3,1),(4,2)}A = \{(1,4), (2,3), (3,1), (4,2)\}. The links cross.
  • One-to-many and unaligned words. For the source "je ne vais pas" and the target "I do not go", the directional alignment is a=(1,3,4,3)a = (1, 3, 4, 3): "je" to "I", "ne" and "pas" both to "not", and "vais" to "go". The word "do" has no link. In the other direction, with "I do not go" as source, "not" can link to only one of "ne" and "pas", so neither direction alone gives the alignment that a person would draw.
  • Counting. A pair with m=4m = 4 and l=4l = 4 has 54=6255^4 = 625 directional alignments with the null word and 216=655362^{16} = 65536 link sets.

Known algorithms

The cost is per sentence pair, with lengths mm and ll, once the model parameters are known. Training repeats an E step that sums over alignments.

Model or method Best alignment Cost Note
IBM Model 1 exact, each word on its own Θ(lm)\Theta(l m) aj=arg⁡max⁡it(fj∣ei)a_j = \arg\max_i t(f_j \mid e_i)
IBM Model 2, fast_align exact, each word on its own Θ(lm)\Theta(l m) the score has a position factor
HMM alignment model exact, by the Viterbi algorithm Θ(ml2)\Theta(m l^2) links depend on the previous link
IBM Model 3 approximate, by hill climbing polynomial per step exact is NP-hard
grow-diag-final combines two directions O(lm)O(l m) per pass a heuristic
one-to-one with scores exact, by the Hungarian algorithm O(n3)O(n^3) with n=max⁡(l,m)n = \max(l, m) a matching

Under Models 1 and 2, p(f,a∣e)p(f, a \mid e) is a product of one factor for each source word, and each factor depends only on aja_j. So the maximum over aa is the product of the maxima over each aja_j. Under the HMM model the factor of aja_j also depends on aj−1a_{j-1}, and dynamic programming over jj gives the exact answer.

AlgorithmTimeSpacePropertiesCode
Fast alignΘ(n m l) worstΘ(l) extradeterministicnot exactofflineiterative1 language
Grow-diag-final symmetrizationO(m l (m + l)) worstO(m l) extradeterministicnot exactofflineiterative1 language

Bounds

  • Upper bounds. The table above gives Θ(lm)\Theta(l m) for Models 1 and 2 and Θ(ml2)\Theta(m l^2) for the HMM model, in the real RAM model with table lookups of constant cost.
  • Search space. There are (l+1)m(l + 1)^m directional alignments and 2lm2^{l m} link sets, so enumeration is exponential. The tests of the model pages use it only to check the exact algorithms.
  • Hardness. For IBM Models 3, 4 and 5, finding the Viterbi alignment is NP-hard, and computing p(f∣e)p(f \mid e), the sum over all alignments, is #P-complete (Udupa and Maji 2006). So the best alignment has no polynomial algorithm unless P = NP, and the sum has none unless P = #P. Training these models uses the HMM model or Model 2 for a start and sums over a neighbourhood of the best alignment found by hill climbing (Brown et al. 1993).

Reductions

  • Viterbi alignment to a path in a DAG. Under the HMM model, the best alignment is a longest path in a layered graph with one layer for each source word and one node for each target position, which dynamic programming on a DAG solves.
  • One-to-one alignment to bipartite matching. With a score for each link and at most one link for each word, the best alignment is a maximum weight matching in the complete bipartite graph between the two sentences.
  • From sentence alignment. Word alignment needs aligned sentence pairs, which sentence alignment produces from aligned documents. Sentence alignment is monotone, so a dynamic program like edit distance solves it; word alignment allows crossing links and has no such order.

Applications

  • Phrase-based translation. Phrase pair extraction takes all phrase pairs that are consistent with the symmetrized links, and the phrase-based translation model scores them.
  • Lexicon learning. The table t(f∣e)t(f \mid e) that the models learn while aligning is a probabilistic bilingual dictionary.
  • Analysis of neural translation. The attention weights of an encoder-decoder model can be turned into links and compared with the links of these models.
  • Speech. Forced alignment is a related problem that links audio frames to words of a known transcript, also with an HMM and the Viterbi algorithm, but with monotone links.

References

  1. Brown, Della Pietra, Della Pietra and Mercer 1993, the definition of an alignment as a set of connections between word positions, with the empty cept, and Models 1 to 5 with their Viterbi alignments
  2. Och and Ney 2003, the statistical alignment models, the symmetrization of the two directions, and the evaluation with sure and possible links
  3. Udupa and Maji 2006, the hardness of the Viterbi alignment for IBM Models 3 to 5
  4. Philipp Koehn, Statistical Machine Translation, Cambridge University Press, 2010, Chapter 4 (word-based models), Section 4.5 (word alignment)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a contract.yaml