0% found this document useful (0 votes)
91 views86 pages

Lesson 13 - Machine Translation

Uploaded by

Pim Pat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views86 pages

Lesson 13 - Machine Translation

Uploaded by

Pim Pat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Machine Translation

NLP II 2025
Jakapun Tachaiya (Ph.D.)

1
Outline
- What is Machine Translation?
- Parallel Corpus
- Machine Translation Model
- MT Evaluation

2
Machine Translation
Machine Translation (MT) is the task of translating a sentence or a paragraph from one
language (the source language) to another language (the target language).

● Need: A pair of sentences in different language!

3
Machine Translation Applications

4
Machine Translation Applications

[Link] 5
Machine Translation Applications

6
MT Requirements
1. Parallel corpus - collections of translations, typically in two languages, that are
aligned at the sentence or phrase level.

a. English <-> Thai

b. Thai <-> Chinese

2. Machine translation models

7
Parallel Corpus
en_text th_text

Just as before, it will be up to the Council to decide the direction เชนเดียวกับเมื่อกอน สภาเปนผูที่จะตัดสินใจทิศทางและกระบวนการ
and process.

In December, he had predicted a 5 percent growth rate. ในเดือนธันวาคม เขาคาดวาจะมีอัตราการเติบโต 5 เปอรเซ็นต

Character actor Hume Cronyn, 91, died Sunday at his home in นักแสดงระดับตํานาน ฮูม โครนีน เสียชีวิตในวัย 91 ปวันอาทิตยที่ผานมาที่บาน
Connecticut. ของเขาในคอนเนตทิคัต

On May 22, 2002, a man walking his dog came across some of เมื่อวันที่ 22 พฤษภาคม 2002 ชายคนหนึ่งพบกระดูกของเลวีบางสวนระหวาง
Levy's bones in Washington's Rock Creek Park. พาสุนัขของเขาเดินเลนในสวนสาธารณะร็อคครีกพารคในวอชิงตัน

The bodies of 18 illegal Mexican immigrants who died from รางของผูอพยพชาวเม็กซิกัน 18 คนที่เสียชีวิตเนื่องจากหายใจไมออกและ
suffocation and heat exhaustion were discovered on Wednesday ออนเพลียจากความรอนถูกพบเมื่อวันพุธที่ผานมาในรถพวงเทรลเลอรที่ถูกจอด
in a packed tractor trailer abandoned at a rest stop. ทิ้งไวที่จุดพักรถ

According to the survey, last years identity theft losses to จากการสํารวจพบวาการโจรกรรมขอมูลสวนบุคคลเมื่อปที่แลวทําใหเกิดความ


businesses and financial institutions totaled nearly $48 billion and เสียหายกับธุรกิจและสถาบันการเงินรวมมูลคาเกือบ 48 พันลานดอลลาร
consumer victims reported $5 billion in out-of-pocket expenses. สหรัฐและผูบริโภคที่ตกเปนเหยื่อมีรายงานวาตองจายถึง 5 พันลาน
ดอลลารสหรัฐ

"This is not unanticipated," Chief Deputy District Attorney John “นี่ไมใชสิ่งที่เกินคาดหมาย” จอหน โกลด รองอัยการเขตกลาวเมื่อวันจันทร
Goold said Monday.

Muhammad and fellow sniper suspect Lee Boyd Malvo, who goes มูฮัมหมัดและลี บอยด มัลโว ผูตองหารวมในคดีซุมยิง ถูกไตสวนคดีเมื่อวันที่ 10
on trial Nov. 10, were arrested Oct. 24, 2002, at a Maryland พฤศจิกายน ถูกจับกุมเมื่อวันที่ 24 ตุลาคม 2002 ที่จุดพักรถบนทางหลวง
highway rest stop. แมริแลนด
Scb-mt-en-th-2020 8
Parallel Corpus

9
Machine translation models
Statistical Model Sequence to Sequence Model

10
Parallel Corpus

11
12
Parallel corpus มาจากไหน
แหลงขอมูล ✅ขอดี ⚠ ขอเสีย

1. จางนักแปล ● คุณภาพการแปลสูง ● แพงมาก (2-10+ บาท/ประโยค)


● บางคูภาษาหายาก

2. เอกสารและประกาศของหนวย ● ฟรี ● domain อาจจะไมตรงกับที่อยากนํา


งานตาง ๆ
● เยอะ ไปใช
● คุณภาพการแปลสูงมาก
● สวนใหญแปลประโยคตอ
ประโยค

3. ขูดมาจากอินเตอรเน็ต ● ฟรี ● ลิขสิทธิ์อาจเปนปญหาได


● เยอะ ● Document + Sentence alignment
ทําไดยาก
● คุณภาพคอนขางหลากหลาย ควบคุม
ไดยาก

13
Parallel corpora ที่เดน ๆ

14
เอกสารและประกาศของหนวยงานตาง ๆ
Typical Pipeline

● หาเว็บทีนาจะมีสองภาษาขนานกัน
● document alignment หา web page ที่นาจะขนานกัน
● sentence alignment หาคูประโยคที่นาจะขนานกัน
● เลื้อยไปเว็บอื่น ๆ (web crawling) ที่มีลิงคจากหนาเว็บนั้น

15
Parallel Corpus - Official Documents
แผนพัฒนาเศรษฐกิจและสังคมแหงชาติ ฉบับที่ ๑๑

16
17
18
Scraped Corpus

19
Machine Translation Models

20
Why do We Need Translation Models?

I love learning English.

ฉันชอบเรียนภาษาอังกฤษ

What problem can we encounter in other cases?

21
Why do We Need Translation Models?

I love learning natural language processing.

ฉันชอบเรียนการประมวลผลภาษาธรรมชาติ

Misalignment of languages

22
Why do We Need Translation Models?

Agriculture is the bread and butter of Thai people.

การทําเกษตรกรรมเปนขนมปงและเนยของคนไทย

Different context meaning

23
Machine Translation Models
● Rule-based MT Statistical MT Neural MT

[Link] 24
Machine Translation Models
1. Rule-based MT

2. Statistical MT

a. Phrase-based MT

3. Neural MT

25
Rule-based MT
Rule-based systems

● build dictionaries

● write transformation rules

● refine, refine, refine

26
Machine Translation Models
1. Rule-based MT

2. Statistical MT

a. Phrase-based MT

3. Neural MT

27
Statistical MT
Core idea: Learn a probabilistic model from data

● Use statistical data from a corpus

● argmaxy P(Y|X) = argmaxy P(X|Y) P(Y) Y = targeted language, X = original language

28
29
P(X|Y) P(Y)
Translation Model Language Model

30
Translation Model
Klein
Y #(Y,Klein) Y P(Y|Klein)

small 400 small 0.4

little 400 little 0.4

short 100 short 0.1

minor 60 minor 0.06

petty 40 petty 0.04

Translation probability of P(X|Y) = Count(X,Y)/Count(Y)


31
Language Model
● P(Y) : Sentence probability in language.

32
argmaxy P(Y|X) = argmaxy P(X|Y) P(Y)

y = sentence ตองลองคํานวณคะแนนจากประโยคที่เปนไปไดในภาษาอังกฤษ 33
Issues with Statistical Models - Translation Model
● No word Alignment on parallel corpus

● Parallel corpus คือ ชุดประโยคคูขนาน แตไมไดบอกวาคําไหนแปลเปนคําไหน

○ ถาเรารูคําไหน align กับคําไหน ก็สบายไปแลว

I love learning natural language processing.

ฉันชอบเรียนการประมวลผลภาษาธรรมชาติ 34
Issues with Statistical Models - Translation Model
● No word Alignment on parallel corpus

● However, it can be learned with EM algorithms

I love learning natural language processing.

ฉันชอบเรียนการประมวลผลภาษาธรรมชาติ
35
Word Alignment
● Word Alignment can be learned with EM algorithms

36
37
Issues with Statistical Models - Translation Model

● Alignment can be Hard

38
Issues with Statistical Models - Language Model
● Sentence probability in language.

● N-gram language model.

○ P(w1, w2, w3, …, wn)

P(I, want, to, eat, Chinese, food) = P(I) x P(want|I) x P(to| I, want) x P(eat|I, want, to)
x P(Chinese|I, want, to, eat) x P(food|I, want, to,
eat, Chinese)

39
Issues with Statistical Models - Language Model
P(I, want, to, eat, Chinese, food) = P(I) x P(want|I) x P(to| I, want) x P(eat|I, want, to)
x P(Chinese|I, want, to, eat) x P(food|I, want, to,
eat, Chinese)

40
Issues with Statistical Models - Language Model
P(I, want, to, eat, Chinese, food) = P(I) x P(want|I) x P(to| I, want) x P(eat|I, want, to)
x P(Chinese|I, want, to, eat) x P(food|I, want, to,
eat, Chinese)

41
Decoding
● การประกอบคําแปลเพื่อหาประโยคที่ดีที่สุด

score(คําแปล, ตนฉบับ) = adequacyScore(คําแปล, ตนฉบับ) + fluencyScore(คําแปล)

argmaxy P(Y|X) = argmaxy P(X|Y) P(Y)

42
เงื่อนไขของ Scoring Function

43
Search หาคําแปลที่ดี(ที่สุด?)
● Exhaustive search คนหาแบบหมดจด
● Greedy search คนหาแบบละโมบ
● Beam search คนหาแบบลําแสง

44
Exhaustive Search Il m'a entarté

45
Exhaustive Search (Viterbi)
● เปนไปไมได เพราะภาษามีความเปนอนันต
● ถาอยากลองทุกประโยคที่มีความยาว k คํา และ vocab size = V เราจะตองลอง
ทั้งหมด Vk ประโยค
● 30,00010 = เยอะเกินสมองมนุษยจะเขาใจ

46
Greedy Search Il m'a entarté

● เลือกคําที่โอกาศเกิดมาที่สุด เเลวตัดคําอื่นทิ้ง

47
Greedy Search
● เเตละ step เก็บตัวที่ดีที่สุดไว 1 คํา
● เร็วดี ถามี k คํา เเละ v vocab จะใชเวลาเทากับ kv
● แตถาผิดตอนตนๆ มันจะสงผลไปถึงที่เหลือทั้งหมด

Beam Search
● แตละ step เก็บ hypothesis เอาไว k ตัว
● แตละ hypothesis เอามาขยายเพิ่มอีกคํา

48
49
50
51
52
53
54
Beam Search จบยังไง
● expand ไปเรื่อยๆ จนกวาจะเจอ <END> ถือวา สมบูรณ
● Hypothesis ไหนยังไมเสร็จก็ search ตอไปจนกวาจะ ถึงความยาวสูงสุด
● หยุดตอนไดคําแปลที่สมบูรณจํานวนที่ตองการ

Beam search decoding เปนวิธีการนํา translation model และ scoring model อื่นๆ ไป
ใชในการแปล ประโยคจริง ๆไมไดผลที่ดีที่สุด แตวาเร็วและไดผลดีแบบยอมรับได
55
Machine Translation Models
1. Rule-based MT

2. Statistical MT

a. Phrase-based MT

3. Neural MT

56
Phase-based Machine Translation
แปลเปนกอนๆ

● บางสวนของประโยคควรจะถูกแปลทั้งกอนพรอมกัน
● เปลี่ยนจาก lexical translation table เปน phrase translation table

57
สกัด Phrase alignment
● phrase : ประกอบดวยคําที่อยูติดกันทั้ง
สองภาษา
○ Bi-gram, tri-gram,...etc
○ ไมไดหมายถึงวลี
● ถาคําที่อยูใน phrase มี word alignment
จะตองเอาไปทุกคําไป รวมใน phrase

58
Phrase ไมใช Constituent
ตาราง word alignment 1 อันสามารถ
ดึงคูของ alignment ออกมาไดเยอะ

● assumes that he

● geht davon aus, dass

59
60
Phrase Translation Table
● ดึง phrases ออกมาใหหมดจาก word alignment (ซํา้ก็นับ)

● เจอปญหาเชนเดียวกับ Starisical language model


○ Sparsity of training dataset - โอกาศในการเจอ phrase ตางๆ มีนอยในกรณี
phrase ยาวๆเเละ คนไมคอยใช

61
Lexical vs Phrase Translation Table

62
e: english
f: foreign
Log-linear model a: attributes อื่นๆ เชน การหางของคําในประโยค จํานวนคํา จํานวน
phrase Bi-directional alignment แหลงความรูอื่น ๆ

Phrase translation table

score/attribute อื่นๆ

Language model

63
Statistical Models
● The best systems were extremely complex.

● Systems had many separately-designed subcomponents.

○ Issues with word alignment on Translation Model


■ Challenge in finding the right word alignment.

■ Different syntax in parallel languages.

■ Lack of long term context dependency.

○ Issues with sentence probability on Language Model


■ Can’t directly estimate probability on a long sentence.
64
Machine Translation Models
1. Rule-based MT

2. Statistical MT

a. Phrase-based MT

3. Neural MT

65
Neural Machine Translation
Recurrent neural network (Encoder - Decoder)

Example from [Link] 66


Neural Machine Translation
Recurrent neural network (Encoder - Decoder)

67
Neural Machine Translation
Encoder - Decoder in action

68
Neural Machine Translation
Recurrent neural network (Encoder)
● Allow flexible length of input.
● Learn context vector of input language.

69
Neural Machine Translation
Recurrent neural network (Decoder)
● No word alignment needed.

70
Neural Machine Translation
Recurrent neural network (Encoder - Decoder)

● Bottleneck problem

71
Neural Machine Translation
Attention mechanism - To fix bottleneck on context vector

72
Compare MT models

Rule-based Statistical model Neural model

Strength ● Create specific rules ● Easy to trace the ● Long context


based on linguistic statistical probabilities understanding
nature. of translated sentence.

Weakness ● High maintenance ● Very complex ● Resource


on rules translation and language intensive on both
models data and model
training

73
Evaluation of MT Models

Image from Syncedreview article 74


MT Evaluation

75
MT vs Sequence Tagging
MT ไมไดมีจํานวน tag เทากับจํานวนคําเสมอไป

● Accuracy, F1-score จะใชไมได

76
การแปลไมมี ground truth แทๆ

77
Machine Translation Evaluation

1. Human evaluation

2. Metric evaluation

78
Human evaluation: The gold standard

Original: El rápido zorro marrón saltó sobre el perro perezoso.

Translate 1: The quick brown fox jumped over the lazy dog.

Translate 2: The fast brown fox pounced over the indolent dog.

Translate 3: The quick brown fox jumped on the lazy dog.

Adequacy: Fluency:
• คําแปลสื่อความหมายเดียวกับประโยค input มั้ย • ฟงดูเหมือนภาษาที่เจาของภาษาพูดรึเปลา
• สาระขาด เกิน หรือบิดเบือนมั้ย • ผิดไวยากรณมั้ย ใชคําผิดไมเหมาะกับความหมายหรือเปลา

79
Human evaluation: The gold standard
Original: El rápido zorro marrón saltó sobre el perro perezoso.

Translate 1: The quick brown fox jumped over the lazy dog.

Translate 2: The fast brown fox pounced over the indolent dog.

Translate 3: The quick brown fox jumped on the lazy dog.

80
Subjective in scoring

81
การวัดความพองกันใน score 5 ระดับ

Kappa score still not


good in practical

82
จัดลําดับคุณภาพของการแปลผาน pairwise comparison

83
Metric Evaluation (automatic)
BLEU Score (Bilingual Evaluation Understudy)

● Evaluate the target sentence based on the overlapped words

84
85
Conclusion on MT
● A task of translating a text from one language to another.
● Requirement
1. Parallel corpus
2. Machine translation models
● Thing to consider when choosing MT models
1. In-context meaning of words
2. Word/phase alignment
3. Performance-to-Cost of inference

86

You might also like