Natural Language Processing (CSEP 517): Machine Translation Noah - - PowerPoint PPT Presentation

natural language processing csep 517 machine translation
SMART_READER_LITE
LIVE PREVIEW

Natural Language Processing (CSEP 517): Machine Translation Noah - - PowerPoint PPT Presentation

Natural Language Processing (CSEP 517): Machine Translation Noah Smith 2017 c University of Washington nasmith@cs.washington.edu May 15, 2017 1 / 59 To-Do List Online quiz: due Sunday (Jurafsky and Martin, 2008, ch. 25), Collins


slide-1
SLIDE 1

Natural Language Processing (CSEP 517): Machine Translation

Noah Smith

c 2017 University of Washington nasmith@cs.washington.edu

May 15, 2017

1 / 59

slide-2
SLIDE 2

To-Do List

◮ Online quiz: due Sunday ◮ (Jurafsky and Martin, 2008, ch. 25), Collins (2011, 2013) ◮ A5 due May 28 (Sunday)

2 / 59

slide-3
SLIDE 3

Evaluation

Intuition: good translations are fluent in the target language and faithful to the

  • riginal meaning.

Bleu score (Papineni et al., 2002):

◮ Compare to a human-generated reference translation ◮ Or, better: multiple references ◮ Weighted average of n-gram precision (across different n)

There are some alternatives; most papers that use them report Bleu, too.

3 / 59

slide-4
SLIDE 4

Warren Weaver to Norbert Wiener, 1947

One naturally wonders if the problem of translation could be conceivably treated as a problem in cryptography. When I look at an article in Russian, I say: ‘This is really written in English, but it has been coded in some strange symbols. I will now proceed to decode.’

4 / 59

slide-5
SLIDE 5

Noisy Channel Models

Review

A pattern for modeling a pair of random variables, X and Y : source − → Y − → channel − → X

5 / 59

slide-6
SLIDE 6

Noisy Channel Models

Review

A pattern for modeling a pair of random variables, X and Y : source − → Y − → channel − → X

◮ Y is the plaintext, the true message, the missing information, the output

6 / 59

slide-7
SLIDE 7

Noisy Channel Models

Review

A pattern for modeling a pair of random variables, X and Y : source − → Y − → channel − → X

◮ Y is the plaintext, the true message, the missing information, the output ◮ X is the ciphertext, the garbled message, the observable evidence, the input

7 / 59

slide-8
SLIDE 8

Noisy Channel Models

Review

A pattern for modeling a pair of random variables, X and Y : source − → Y − → channel − → X

◮ Y is the plaintext, the true message, the missing information, the output ◮ X is the ciphertext, the garbled message, the observable evidence, the input ◮ Decoding: select y given X = x.

y∗ = argmax

y

p(y | x) = argmax

y

p(x | y) · p(y) p(x) = argmax

y

p(x | y) channel model · p(y)

  • source model

8 / 59

slide-9
SLIDE 9

Bitext/Parallel Text

Let f and e be two sequences in V† (French) and ¯ V† (English), respectively. We’re going to define p(F | e), the probability over French translations of English sentence e. In a noisy channel machine translation system, we could use this together with source/language model p(e) to “decode” f into an English translation. Where does the data to estimate this come from?

9 / 59

slide-10
SLIDE 10

IBM Model 1

(Brown et al., 1993)

Let ℓ and m be the (known) lengths of e and f. Latent variable a = a1, . . . , am, each ai ranging over {0, . . . , ℓ} (positions in e).

◮ a4 = 3 means that f4 is “aligned” to e3. ◮ a6 = 0 means that f6 is “aligned” to a special null symbol, e0.

p(f | e, m) =

  • a1=0

  • a2=0

· · ·

  • am=0

p(f, a | e, m) =

  • a∈{0,...,ℓ}m

p(f, a | e, m) p(f, a | e, m) =

m

  • i=1

p(ai | i, ℓ, m) · p(fi | eai) =

m

  • i=1

1 ℓ + 1 · θfi|eai =

  • 1

ℓ + 1 m m

  • i=1

θfi|eai

10 / 59

slide-11
SLIDE 11

Example: f is German

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 4, . . . p(f, a | e, m) = 1 17 + 1 · θNoahs|Noah’s

11 / 59

slide-12
SLIDE 12

Example: f is German

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 4, 5, . . . p(f, a | e, m) = 1 17 + 1 · θNoahs|Noah’s · 1 17 + 1 · θArche|ark

12 / 59

slide-13
SLIDE 13

Example: f is German

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 4, 5, 6, . . . p(f, a | e, m) = 1 17 + 1 · θNoahs|Noah’s · 1 17 + 1 · θArche|ark · 1 17 + 1 · θwar|was

13 / 59

slide-14
SLIDE 14

Example: f is German

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 4, 5, 6, 8, . . . p(f, a | e, m) = 1 17 + 1 · θNoahs|Noah’s · 1 17 + 1 · θArche|ark · 1 17 + 1 · θwar|was · 1 17 + 1 · θnicht|not

14 / 59

slide-15
SLIDE 15

Example: f is German

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 4, 5, 6, 8, 7, . . . p(f, a | e, m) = 1 17 + 1 · θNoahs|Noah’s · 1 17 + 1 · θArche|ark · 1 17 + 1 · θwar|was · 1 17 + 1 · θnicht|not · 1 17 + 1 · θvoller|filled

15 / 59

slide-16
SLIDE 16

Example: f is German

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 4, 5, 6, 8, 7, ?, . . . p(f, a | e, m) = 1 17 + 1 · θNoahs|Noah’s · 1 17 + 1 · θArche|ark · 1 17 + 1 · θwar|was · 1 17 + 1 · θnicht|not · 1 17 + 1 · θvoller|filled · 1 17 + 1 · θProductionsfactoren|?

16 / 59

slide-17
SLIDE 17

Example: f is German

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 4, 5, 6, 8, 7, ?, . . . p(f, a | e, m) = 1 17 + 1 · θNoahs|Noah’s · 1 17 + 1 · θArche|ark · 1 17 + 1 · θwar|was · 1 17 + 1 · θnicht|not · 1 17 + 1 · θvoller|filled · 1 17 + 1 · θProductionsfactoren|? Problem: This alignment isn’t possible with IBM Model 1! Each fi is aligned to at most one eai!

17 / 59

slide-18
SLIDE 18

Example: f is English

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 0, . . . p(f, a | e, m) = 1 10 + 1 · θMr|null

18 / 59

slide-19
SLIDE 19

Example: f is English

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 0, 0, 0, . . . p(f, a | e, m) = 1 10 + 1 · θMr|null · 1 10 + 1 · θPresident|null · 1 10 + 1 · θ,|null

19 / 59

slide-20
SLIDE 20

Example: f is English

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 0, 0, 0, 1, . . . p(f, a | e, m) = 1 10 + 1 · θMr|null · 1 10 + 1 · θPresident|null · 1 10 + 1 · θ,|null · 1 10 + 1 · θNoah’s|Noahs

20 / 59

slide-21
SLIDE 21

Example: f is English

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 0, 0, 0, 1, 2, . . . p(f, a | e, m) = 1 10 + 1 · θMr|null · 1 10 + 1 · θPresident|null · 1 10 + 1 · θ,|null · 1 10 + 1 · θNoah’s|Noahs · 1 10 + 1 · θark|Arche

21 / 59

slide-22
SLIDE 22

Example: f is English

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 0, 0, 0, 1, 2, 3, . . . p(f, a | e, m) = 1 10 + 1 · θMr|null · 1 10 + 1 · θPresident|null · 1 10 + 1 · θ,|null · 1 10 + 1 · θNoah’s|Noahs · 1 10 + 1 · θark|Arche · 1 10 + 1 · θwas|war

22 / 59

slide-23
SLIDE 23

Example: f is English

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 0, 0, 0, 1, 2, 3, 5, . . . p(f, a | e, m) = 1 10 + 1 · θMr|null · 1 10 + 1 · θPresident|null · 1 10 + 1 · θ,|null · 1 10 + 1 · θNoah’s|Noahs · 1 10 + 1 · θark|Arche · 1 10 + 1 · θwas|war · 1 10 + 1 · θfilled|voller

23 / 59

slide-24
SLIDE 24

Example: f is English

Mr President , Noah's ark was filled not with production factors , but with living creatures . Noahs Arche war nicht voller Produktionsfaktoren , sondern Geschöpfe .

a = 0, 0, 0, 1, 2, 3, 5, 4, . . . p(f, a | e, m) = 1 10 + 1 · θMr|null · 1 10 + 1 · θPresident|null · 1 10 + 1 · θ,|null · 1 10 + 1 · θNoah’s|Noahs · 1 10 + 1 · θark|Arche · 1 10 + 1 · θwas|war · 1 10 + 1 · θfilled|voller · 1 10 + 1 · θnot|nicht

24 / 59

slide-25
SLIDE 25

How to Estimate Translation Distributions?

This is a problem of incomplete data: at training time, we see e and f, but not a.

25 / 59

slide-26
SLIDE 26

How to Estimate Translation Distributions?

This is a problem of incomplete data: at training time, we see e and f, but not a. Classical solution is to alternate:

◮ Given a parameter estimate for θ, align the words. ◮ Given aligned words, re-estimate θ.

Traditional approach uses “soft” alignment.

26 / 59

slide-27
SLIDE 27

“Complete Data” IBM Model 1

Let the training data consist of N word-aligned sentence pairs: e(1)

1 , f (1), a(1), . . . , e(N), f (N), a(N).

Define: ι(k, i, j) =

  • 1

if a(k)

i

= j

  • therwise

Maximum likelihood estimate for θf|e: c(e, f) c(e) =

N

  • k=1
  • i:f(k)

i

=f

  • j:e(k)

j

=e

ι(k, i, j)

N

  • k=1

m(k)

  • i=1
  • j:e(k)

j

=e

ι(k, i, j)

27 / 59

slide-28
SLIDE 28

MLE with “Soft” Counts for IBM Model 1

Let the training data consist of N “softly” aligned sentence pairs, e(1)

1 , f (1), , . . . , e(N), f (N).

Now, let ι(k, i, j) be “soft,” interpreted as: ι(k, i, j) = p(a(k)

i

= j) Maximum likelihood estimate for θf|e:

N

  • k=1
  • i:f(k)

i

=f

  • j:e(k)

j

=e

ι(k, i, j)

N

  • k=1

m(k)

  • i=1
  • j:e(k)

j

=e

ι(k, i, j)

28 / 59

slide-29
SLIDE 29

Expectation Maximization Algorithm for IBM Model 1

  • 1. Initialize θ to some arbitrary values.
  • 2. E step: use current θ to estimate expected (“soft”) counts.

ι(k, i, j) ← θf(k)

i

|e(k)

j

ℓ(k)

  • j′=0

θf(k)

i

|e(k)

j′

  • 3. M step: carry out “soft” MLE.

θf|e ←

N

  • k=1
  • i:f(k)

i

=f

  • j:e(k)

j

=e

ι(k, i, j)

N

  • k=1

m(k)

  • i=1
  • j:e(k)

j

=e

ι(k, i, j)

29 / 59

slide-30
SLIDE 30

Expectation Maximization

◮ Originally introduced in the 1960s for estimating HMMs when the states really are

“hidden.”

◮ Can be applied to any generative model with hidden variables. ◮ Greedily attempts to maximize probability of the observable data, marginalizing

  • ver latent variables. For IBM Model 1, that means:

max

θ N

  • k=1

pθ(f (k) | e(k)) = max

θ N

  • k=1
  • a

pθ(f (k), a | e(k))

◮ Usually converges only to a local optimum of the above, which is in general not

convex.

◮ Strangely, for IBM Model 1 (and very few other models), it is convex!

30 / 59

slide-31
SLIDE 31

IBM Model 2

(Brown et al., 1993)

Let ℓ and m be the (known) lengths of e and f. Latent variable a = a1, . . . , am, each ai ranging over {0, . . . , ℓ} (positions in e).

◮ E.g., a4 = 3 means that f4 is “aligned” to e3.

p(f | e, m) =

  • a∈{0,...,n}m

p(f, a | e, m) p(f, a | e, m) =

m

  • i=1

p(ai | i, ℓ, m) · p(fi | eai) = δai|i,ℓ,m · θfi|eai

31 / 59

slide-32
SLIDE 32

IBM Models 1 and 2, Depicted

x1 x2 x3 x4 hidden Markov model y1 y2 y3 y4 f1 f2 f3 f4 IBM 1 and 2 a1 a2 a3 a4 e e e e

32 / 59

slide-33
SLIDE 33

Variations

◮ Dyer et al. (2013) introduced a new parameterization:

δj|i,ℓ,m ∝ exp −λ

  • i

m − j ℓ

  • (This is called fast align.)

◮ IBM Models 3–5 (Brown et al., 1993) introduced increasingly more powerful

ideas, such as “fertility” and “distortion.”

33 / 59

slide-34
SLIDE 34

From Alignment to (Phrase-Based) Translation

Obtaining word alignments in a parallel corpus is a common first step in building a machine translation system.

  • 1. Align the words.
  • 2. Extract and score phrase pairs.
  • 3. Estimate a global scoring function to optimize (a proxy for) translation quality.
  • 4. Decode French sentences into English ones.

(We’ll discuss 2–4.) The noisy channel pattern isn’t taken quite so seriously when we build real systems, but language models are really, really important nonetheless.

34 / 59

slide-35
SLIDE 35

Phrases?

Phrase-based translation uses automatically-induced phrases . . . not the ones given by a phrase-structure parser.

35 / 59

slide-36
SLIDE 36

Examples of Phrases

Courtesy of Chris Dyer.

German English p( ¯ f | ¯ e) das Thema the issue 0.41 the point 0.72 the subject 0.47 the thema 0.99 es gibt there is 0.96 there are 0.72 morgen tomorrow 0.90 fliege ich will I fly 0.63 will fly 0.17 I will fly 0.13

36 / 59

slide-37
SLIDE 37

Phrase-Based Translation Model

Originated by Koehn et al. (2003).

R.v. A captures segmentation of sentences into phrases, alignment between them, and reordering. to the conference Morgen fliege ich nach Pittsburgh zur Konferenz Tomorrow I will fly in Pittsburgh

e f a

p(f, a | e) = p(a | e) ·

|a|

  • i=1

p( ¯ f i | ¯ ei)

37 / 59

slide-38
SLIDE 38

Extracting Phrases

After inferring word alignments, apply heuristics.

38 / 59

slide-39
SLIDE 39

Extracting Phrases

After inferring word alignments, apply heuristics.

39 / 59

slide-40
SLIDE 40

Extracting Phrases

After inferring word alignments, apply heuristics.

40 / 59

slide-41
SLIDE 41

Extracting Phrases

After inferring word alignments, apply heuristics.

41 / 59

slide-42
SLIDE 42

Extracting Phrases

After inferring word alignments, apply heuristics.

42 / 59

slide-43
SLIDE 43

Extracting Phrases

After inferring word alignments, apply heuristics.

43 / 59

slide-44
SLIDE 44

Extracting Phrases

After inferring word alignments, apply heuristics.

44 / 59

slide-45
SLIDE 45

Extracting Phrases

After inferring word alignments, apply heuristics.

45 / 59

slide-46
SLIDE 46

Scoring Whole Translations

s(e, a; f) = log p(e) language model + log p(f, a | e)

  • translation model

Remarks:

◮ Segmentation, alignment, reordering are all predicted as well (not marginalized). ◮ This does not factor nicely.

46 / 59

slide-47
SLIDE 47

Scoring Whole Translations

s(e, a; f) = log p(e) language model + log p(f, a | e)

  • translation model

+ log p(e, a | f)

  • reverse t.m.

Remarks:

◮ Segmentation, alignment, reordering are all predicted as well (not marginalized). ◮ This does not factor nicely. ◮ I am simplifying!

◮ Reverse translation model typically included. 47 / 59

slide-48
SLIDE 48

Scoring Whole Translations

s(e, a; f) = βl.m. log p(e) language model +βt.m. log p(f, a | e)

  • translation model

+ βr.t.m.log p(e, a | f)

  • reverse t.m.

Remarks:

◮ Segmentation, alignment, reordering are all predicted as well (not marginalized). ◮ This does not factor nicely. ◮ I am simplifying!

◮ Reverse translation model typically included. ◮ Each log-probability is treated as a “feature” and weights are optimized for Bleu

performance.

48 / 59

slide-49
SLIDE 49

Decoding: Example

Maria no dio una bofetada a la bruja verda Mary not give a slap to the witch green no did not did not give slap slap by to the the the witch hag bawdy green witch

49 / 59

slide-50
SLIDE 50

Decoding: Example

Maria no dio una bofetada a la bruja verda Mary not give a slap to the witch green no did not did not give slap slap by to the the the witch hag bawdy green witch

50 / 59

slide-51
SLIDE 51

Decoding: Example

Maria no dio una bofetada a la bruja verda Mary not give a slap to the witch green no did not did not give slap slap by to the the the witch hag bawdy green witch

51 / 59

slide-52
SLIDE 52

Decoding

Adapted from Koehn et al. (2006).

Typically accomplished with beam search. Initial state: ◦ ◦ . . . ◦

|f|

, “” with score 0 Goal state: • • . . . •

|f|

, e∗ with (approximately) the highest score Reaching a new state:

◮ Find an uncovered span of f for which a phrasal translation exists in the input

( ¯ f, ¯ e)

◮ New state appends ¯

e to the output and “covers” ¯ f.

◮ Score of new state includes additional language model, translation model

components for the global score.

52 / 59

slide-53
SLIDE 53

Decoding Example

Maria no dio una bofetada a la bruja verda Mary not give a slap to the witch green no did not did not give slap slap by to the the the witch hag bawdy green witch

  • ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦, “”, 0

53 / 59

slide-54
SLIDE 54

Decoding Example

Maria no dio una bofetada a la bruja verda Mary not give a slap to the witch green no did not did not give slap slap by to the the the witch hag bawdy green witch

  • ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦, “Mary”, log pl.m.(Mary) + log pt.m.(Maria | Mary)

54 / 59

slide-55
SLIDE 55

Decoding Example

Maria no dio una bofetada a la bruja verda Mary give a slap to the witch green did not slap slap by to the the the witch hag bawdy green witch

  • • ◦ ◦ ◦ ◦ ◦ ◦ ◦, “Mary did not”,

log pl.m.(Mary did not) + log pt.m.(Maria | Mary) + log pt.m.(no | did not)

55 / 59

slide-56
SLIDE 56

Decoding Example

Maria no dio una bofetada a la bruja verda Mary to the witch green did not slap by to the the the witch hag bawdy green witch

  • • • • • ◦ ◦ ◦ ◦, “Mary did not slap”,

log pl.m.(Mary did not slap) + log pt.m.(Maria | Mary) + log pt.m.(no | did not) + log pt.m.(dio una bofetada | slap)

56 / 59

slide-57
SLIDE 57

Machine Translation: Remarks

Sometimes phrases are organized hierarchically (Chiang, 2007). Extensive research on syntax-based machine translation (Galley et al., 2004), but requires considerable engineering to match phrase-based systems. Recent work on semantics-based machine translation (Jones et al., 2012); remains to be seen! Some good pre-neural overviews: Lopez (2008); Koehn (2009)

57 / 59

slide-58
SLIDE 58

References I

Peter F. Brown, Vincent J. Della Pietra, Stephen A. Della Pietra, and Robert L. Mercer. The mathematics of statistical machine translation: Parameter estimation. Computational Linguistics, 19(2):263–311, 1993. David Chiang. Hierarchical phrase-based translation. computational Linguistics, 33(2):201–228, 2007. Michael Collins. Statistical machine translation: IBM models 1 and 2, 2011. URL http://www.cs.columbia.edu/~mcollins/courses/nlp2011/notes/ibm12.pdf. Michael Collins. Phrase-based translation models, 2013. URL http://www.cs.columbia.edu/~mcollins/pb.pdf. Chris Dyer, Victor Chahuneau, and Noah A Smith. A simple, fast, and effective reparameterization of IBM Model 2. In Proc. of NAACL, 2013. Michel Galley, Mark Hopkins, Kevin Knight, and Daniel Marcu. What’s in a translation rule? In Proc. of NAACL, 2004. Bevan Jones, Jacob Andreas, Daniel Bauer, Karl Moritz Hermann, and Kevin Knight. Semantics-based machine translation with hyperedge replacement grammars. In Proc. of COLING, 2012. Daniel Jurafsky and James H. Martin. Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition. Prentice Hall, second edition, 2008. Philipp Koehn. Statistical Machine Translation. Cambridge University Press, 2009. Philipp Koehn, Franz Josef Och, and Daniel Marcu. Statistical phrase-based translation. In Proc. of NAACL, 2003.

58 / 59

slide-59
SLIDE 59

References II

Philipp Koehn, Marcello Federico, Wade Shen, Nicola Bertoldi, Ondrej Bojar, Chris Callison-Burch, Brooke Cowan, Chris Dyer, Hieu Hoang, and Richard Zens. Open source toolkit for statistical machine translation: Factored translation models and confusion network decoding, 2006. Final report of the 2006 JHU summer workshop. Adam Lopez. Statistical machine translation. ACM Computing Surveys, 40(3):8, 2008. Kishore Papineni, Salim Roukos, Todd Ward, and Wei-Jing Zhu. Bleu: a method for automatic evaluation of machine translation. In Proc. of ACL, 2002.

59 / 59