natural language processing - cs.science.cmu.ac.th natural language processing 03 nlp and...

29
Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐ 204471 Artificial Intelligence 1

Upload: doankhanh

Post on 07-May-2018

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

NaturalLanguageProcessing03  NLP and Communication

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

1

Page 2: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

Outline• Communication• Grammars• Syntactic Analysis (Parsing)• Augmented Grammar and Semantic Interpretation•Machine Translation• Speech Recognition Co

mpu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

2

Page 3: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

MACHINETRANSLATION

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

3

Page 4: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

MachineTranslation• เป็นการใช้แปรข้อความจากภาษาธรรมชาติสองภาษา: source  target• ตวัอยา่งการใช้การใช้ machine translation• Rough translation• แปลอตัโนมตัิให้พอเข้าใจ แตจ่ะมีข้อผิดพลาดมาก

• ตวัอยา่งเชน่ google translate หรือบริการไมค่ิดคา่ใช้จา่ยบนเว็บอื่นๆ• Pre‐edited translation• แปลเอกสารที่มีการจํากดัวิธีเขียนอตัโนมตัิ แล้วแก้ตอ่ด้วยมนษุย์• มีรูปแบบคอ่นข้างแนน่อน และศพัท์ที่ใช้จํากดั

• เชน่ คูม่ือการใช้งานที่มีหลายภาษา

• Restricted‐source translation• อตัโนมตัิเตม็รูปแบบ แตไ่ด้เฉพาะกบัข้อความที่มีรูปแบบตามที่กําหนดเทา่นัน้

• เชน่ รายงานสภาพอากาศ

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

4

Page 5: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

ตวัอยา่ง—GoogleTranslateAI is one of the newest fields in science and engineering. Work started in earnest soon after World War II, and the name itself was coined in 1956. Along with molecular biology, AI is regularly cited as the “field I would most like to be in” by scientists in other disciplines.

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

5

AI เป็นหนึง่ในสาขาใหมล่า่สดุในด้านวิทยาศาสตร์และวิศวกรรม เริ่มทํางานอยา่งจริงจงัในเร็ว ๆ นีห้ลงัจากสงครามโลกครัง้ที่สองและชื่อตวัเองได้รับการประกาศเกียรติคณุในปี 1956 พร้อมกบัอณชูีววิทยา AI จะอ้างอยา่งสมํ่าเสมอเป็นฟิลด์ "ผมอยากที่จะอยูใ่น" โดยนกัวิทยาศาสตร์ในสาขาวิชาอื่น ๆ

AI is one of the newest fields in science and engineering. Work began in earnest soon after World War II and the name itself was coined in 1956, along with molecular biology, AI is regularly cited as the field. "I wanted to be in" by scientists in other disciplines.

Page 6: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

อุปสรรคในการทาํ MachineTranslation• คําศพัท์หนึง่คําอาจมีความหมายมากกวา่หนึง่• “เปิด” “switch .. on”, “open”• “on”  “บน”, “เปิด”

• คําแปลอาจจะขึน้อยูก่บัสถานการณ์• “I”  “ผม”, “ฉนั”, “ก”ู, “ข้า”, “ข้าพเจ้า”, “เรา”

• ความกํากวมของประโยค• “ฉนัรักพี่มาก”

• คําศพัท์/รูปประโยคที่เกิดขึน้มาใหม่

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

6

ผู้แปลจะต้องเข้าใจ

บริบทของข้อความนัน้

Page 7: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

ระบบการทาํ MachineTranslation• จะต้องมี models ของภาษาต้นทาง (source) และภาษาปลายทาง (target)• อาจใช้ Interlingua system• เป็น representation ที่กําจดัความกํากวมออกไป

On1(TV) vs. On2(Bottle, Table)• เริ่มจากข้อความในภาษาต้นทางแล้ววิเคราะห์ประโยคทีละขัน้จนได้ interlinguarepresentation แล้วคอ่ยสร้างประโยคในภาษาปลายทาง• ประโยค รูปประโยค ความหมาย interlingua representation  …

• จะต้องแก้ปัญหา:• ต้องมี knowledge representation ของทกุอยา่งครบถ้วน• การ parse ประโยคเป็น interlingua representation• การสร้างประโยคจาก interlingua representation

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

7

Page 8: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

ระบบการทาํ MachineTranslation (ต่อ)• หรืออาจใช้ transfer model แทน• เป็นฐานข้อมลูของกฎ (หรือตวัอยา่ง) การแปล• ถ้าประโยค/ชดุคําตรงกบักฎ/ตวัอยา่ง ก็แปลไปเลย• มีได้ที่ระดบัคําศพัท์ ระดบัไวยากรณ์ หรือระดบัความหมาย

• ตวัอยา่ง:EN[“Happy Birthday”]  TH[“สขุสนัต์วนัเกิด”]EN[Adjective Noun]  TH[Noun Adjective]EN[“if S1 then S2”]  TH[“ถ้า S1 แล้ว S2”]

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

8

Page 9: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

Vauquois Triangle

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

9Interlingua‐based system

Transfer‐based system

Page 10: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

StatisticalMachineTranslation• สร้าง probabilistic model จาก corpus• ไมต่้องมีความเข้าใจทางภาษาหรือมีการเตรียมอะไรเป็นพิเศษ

• ต้องการแคข่้อมลู• ประโยค/ชดุคําในภาษาต้นทาง และ คําแปลในภาษาปลายทาง

• ตวัอยา่ง: การแปลจากภาษาองักฤษ (eng) เป็นภาษาไทย (th) คือการเลือกชดุคําในภาษาไทย th* ที่:

โดยที่ เป็น language model บอกเราวา่ ประโยค th เป็นไปได้แคไ่หนในภาษาไทย

และ เป็น translation model บอกเราวา่ ถ้าให้ประโยค th ในภาษาไทย จะมีความเป็นไปได้แคไ่หนที่คําแปลไปเป็นภาษาองักฤษจะได้ประโยค eng

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

10

Page 11: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

StatisticalMachineTranslation (ต่อ)• เราสร้าง model จาก bilingual corpus• ชดุของคูข่้อความเดียวกนั ในทัง้สองภาษา

• เราสามารถแยกประโยคออกเป็นวลี (phrase) แล้วสร้างคูค่ําแปลของวลีได้• ในการแปล:

1. แยกประโยคออกเป็นวลี

2. แปลวลีแตล่ะตวัโดยใช้คูค่ําแปล

3. ประกอบวลีที่แปลแล้วเข้ามาเป็นประโยคใหม่

• แตว่า่ ในแตล่ะภาษามีตําแหนง่ของวลีตา่งกนั

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

11

Page 12: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

StatisticalMachineTranslation (ต่อ)การจดัลําดบัของวลีที่แปลแล้ว

• สําหรับการเปลี่ยนแปลงของรูปประโยค เราไมส่ามารถจะให้ความนา่จะเป็นกบัทกุลําดบัที่เป็นไปได้ (permutation) ของวลีได้

• เราจะใช้ distortion di แทน• จํานวนคําที่เปลี่ยนของวลี เมื่อเทียบกบัวลีก่อนหน้าในประโยคภาษาต้นทาง

• ตวัอยา่ง: แปลประโยคในภาษาองักฤษประกอบด้วยวลี eng1, eng2,...,engn เป็นชดุวลีภาษาไทย th1, th2,...,thn

• di  คือ ตําแหนง่ที่เปลี่ยนไปของวลี thi เมื่อเทียบกบัวลีที่เคยอยูก่่อนหน้า thi‐1

โดยที่ START(th) คือตําแหนง่ของคําแรกของวลีในประโยคภาษาปลายทางและ END(th) คือตําแหนง่ของคําสดุท้ายในวลี

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

12

Page 13: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

ตวัอยา่ง

• จากประโยค “There is a smelly wumpus sleeping in 2 2”

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

131 2 3 1 2

Page 14: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

StatisticalMachineTranslation (ต่อ)Distortion• หา

• ในประโยคความยาว n คํา, จะมีขนาด 2n‐1 คา่ น้อยกวา่ n! มาก

การคํานวณ

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

14

Page 15: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

ขั้นตอนการสร้าง MachineTranslationหา phrasal  และ distortion  probabilities1. หา parallel texts (ข้อความที่เขียนอยูใ่นหลายภาษา)• บนัทกึการประชมุสหประชาชาติ, web ที่มีหลายภาษา• เชน่ https://hansard.parliament.uk/

2. แยกข้อความเป็นประโยค

3. จบัคูป่ระโยคที่ความหมายตรงกนั— อาจไมเ่ป็น 1:14. แยกประโยคเป็นวลี แล้วจบัคูว่ลีที่เป็นคําแปล

5. คํานวณคา่ distortions6. ใช้ expectation maximization (EM) ในการปรับปรุงการประมาณคา่ความ

นา่จะเป็น

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

15

Page 16: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

SPEECHRECOGNITION

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

16

Page 17: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

SpeechRecognition• คือ การจําแนกแยกแยะชดุคําที่ผู้พดูพดูออกมา (sequence of words) จากสญัญาณเสียง (acoustic signal)• ตวัอยา่งปัญหาใน speech recognition

“Recognize Speech” vs. “Wreck a nice beach”• Segmentation: จะแบง่คําที่ไหน• Coarticulation: เสียงจากคําข้างหน้าปนเข้ากบัเสียงในคําข้างหลงั• Homophones: คําที่ออกเสียงคล้ายกนั• “to”, “two”, “too”• “กาล”, “กาฬ”, “กาญจน์”

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

17

Page 18: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

SpeechRecognition Model• อาจมองเป็นปัญหา โดยที่ : เป็น

และ : เป็น

• ใช้

:: :

:: : :

• หรือ แยกการแจกแจงความนา่จะเป็นออกเป็น acoustic model + language model.

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

18

Page 19: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

AcousticModel•Model ของ เสียงพดู• เราต้องการจะรู้แคว่า่ในสญัญาณเสียงมีคําพดูอะไรบ้าง ดงันัน้จงึไมจ่ําเป็นที่จะต้องเก็บข้อมลูปลีกยอ่ยของคลื่นเสียงไว้

• จะเก็บเสียงพดูในรูปของหนว่ยเสียง (phones)• มีอยูป่ระมาณ 100 เสียงในคําพดู• เชน่เสียงพยญัชนะ สระ

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

19

Page 20: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

ใน

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

20

Page 21: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

SpeechSounds• สญัญาณเสียง สญัญาณเสียงดิจิตลั frame ขนาด 30ms ที่มีสว่นซ้อนกนั• แตล่ะ frame ประกอบด้วย features — ลกัษณะบางอยา่งของสญัญาณเสียง

• เชน่ พลงังานเสียงที่แตล่ะความถี่ mel frequency cepstral coefficient (MFCC)

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

21

Page 22: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

PhoneModel•• หา จาก ของ

• มี

• Phone จะประกอบด้วย 3 สว่น : Onset, Mid, End• เชน่ [t] มี silent Onset, explosive Mid, hissing End

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

22

Page 23: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

PronunciationModel• ตอ่ phones รวมกนัเป็นคําศพัท์

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

23

Page 24: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

LanguageModel• “sealing fan” vs. “ceiling fan”• ภาษาพดูมกัจะมีความแตกตา่งจากภาษาเขียน• ควรจะใช้ corpus ที่มาจากคําพดู เชน่ บทสมัภาษณ์

• Corpus ควรตรงกบังานที่จะใช้ (task‐specific)• จองตัว๋เครื่องบิน ใช้ corpus ที่มาจากบนัทกึบทสนทนาการจองตัว๋เครื่องบิน• ควรจะมีชดุคําศพัท์เฉพาะสําหรับงาน• UI: ถามคําถามที่จํากดัจํานวนคําตอบที่เป็นไปได้

“คณุต้องการจะเดินทางไปเมืองไหนคะ” vs. “มีอะไรใช้ชว่ยคะ”

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

24

Page 25: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

การสร้าง SpeechRecognizer• สว่นประกอบ• language model จาก corpus• signal‐processing algorithms ใช้ความรู้ผู้ เชี่ยวชาญ

• pronunciation models, phone models• โครงสร้างจาก dictionaries, ผู้ เชี่ยวชาญ• สร้าง HMM แล้วฝึกการแจกแจงความนา่จะเป็น

• ปัจจยัที่มีผลตอ่ความถกูต้อง• คณุภาพของสญัญาณเสียง• ขนาดของชดุคําศพัท์ (ยิ่งเลก็ยิ่งดี)• งานที่ใช้ (ยิ่งเฉพาะเจาะจงยิ่งดี)

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

25

Page 26: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

Summary• Temporal Statistical Models• โครงสร้าง, ประเภทของตวัแปร (state, evidence)•Markov assumptions, process.• Inference Tasks• Filtering, prediction, smoothing, most likely explanation.

• HMM• ใช้matrix ในการทํา inference.

• Other models (Kalman filters, Dynamic BN)• Particle filtering

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

26

Page 27: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

Summary•Working with Texts• Language Models• n‐gram

• Application• Text Classification• Information Retrieval• PageRank• HITS• Question answering

• Information Extraction• FA• HMM• CRF

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

27

Page 28: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

Summary(ต่อ)• Communication• Grammar (+ augmented grammar)• PCFG• Lexicalized PCFG• DCG• Semantic Interpretation

• Parsing• CYK

•Machine Translation• Models

• Speech Recognition

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

28

Page 29: Natural Language Processing - cs.science.cmu.ac.th Natural Language Processing 03 NLP and Communication Computer Science, Chiang Mai University ‐‐204471 Artificial Int elligence

Reference• Russell, Peter Norvig Stuart (2009‐12‐01). Artificial Intelligence: A Modern Approach, 3/e. Pearson HE, Inc.. Kindle Edition. • Stuart Russell’s Slides

Compu

ter S

cien

ce, C

hian

g Mai University

 ‐‐20

4471

 Artificial In

telligence

29