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