ใน ep นี้เราจะมาศึกษาอีก Concept นึงที่สำคัญของ NLP คือ Language Model หรือ โมเดลของภาษา ซึ่งถ้าโมเดลของเรามีความสามารถที่จะเข้าใจภาษาโดยภาพรวมได้ดีระดับหนึ่งแล้ว ก็จะส่งผลให้โมเดลนั้นทำงานเฉพาะทาง เช่น ClassificationSentiment Analysis, Machine Translation, Question-Answer ได้ดีขึ้นไปด้วยในตัว

Language Model คืออะไร

Parse tree of the English phrase "John loves Mary" using the Grammatical Framework (GF) shell command 'vp'. Credit https://commons.wikimedia.org/wiki/File:Parse_tree_-_English.png
Parse tree of the English phrase “John loves Mary” using the Grammatical Framework (GF) shell command ‘vp’. Credit https://commons.wikimedia.org/wiki/File:Parse_tree_-_English.png

Language Model คือ โมเดลว่าภาษานั้นเป็นอย่างไร ในทางสถิติคือ Probability Distribution ของลำดับของคำต่าง ๆ ว่าน่าจะเป็นคำอะไร เช่น ถ้าเราเข้าใจภาษาอังกฤษบ้าง เราก็จะพอเดาได้ว่าคำอะไรน่าจะอยู่ในช่องว่าง Somsak is a tall ______. และคำอะไรไม่น่าจะอยู่

ในทางปฏิบัติ เราสามารถใช้วิธี Bag-of-word ดูทีละคำ (Uni-Gram) ทีละหลาย ๆ คำ N-Gram ดูคำที่มาก่อน ดูคำที่มาทีหลัง หรือทั้งสองทิศทาง Bi-direction และใช้โมเดลคณิตศาสตร์ได้หลากหลาย

แต่ในเคสนี้ เราจะใช้ Neural Network แบบ Recurrent Neural Network – RNN แบบหนึ่ง เรียกว่า AWD_LSTM ที่ถูกเทรนด้วย Corpus ข้อความจาก Dumps Wikipedia ภาษาไทย โดยให้โมเดลเดาคำต่อไปเรื่อย ๆ (เป็น Label แบบ Self-supervised Learning)

เมื่อเราได้ Language Model จาก Wikipedia ภาษาไทย มาแล้ว เราสามารถใส่ข้อความภาษาไทยเริ่มต้นเข้าไปให้ Language Model เดาคำที่น่าจะเป็นคำต่อไป หรือก็คือ Generate Text สร้างข้อความใหม่ต่อ ๆ ไปได้

AWD_LSTM Model Architecture

DropConnect sets a randomly selected subset of weights within the network to zero. Credit https://arxiv.org/abs/1906.04569
DropConnect sets a randomly selected subset of weights within the network to zero. Credit https://arxiv.org/abs/1906.04569

AWD_LSTM เป็น LSTM / Recurrent Neural Network (RNN) แบบหนึ่ง ที่มีการใช้ DropOut / DropConnect หลากหลายแบบภายในส่วนต่าง ๆ ของโมเดล อย่างชาญฉลาด จะอธิบายต่อไป

An example model layout for a single DropConnect layer. Credit http://proceedings.mlr.press/v28/wan13.html
An example model layout for a single DropConnect layer. Credit http://proceedings.mlr.press/v28/wan13.html

เรามาเริ่มกันเลยดีกว่า

Open In Colab

แชร์ให้เพื่อน:

Surapong Kanoktipsatharporn on FacebookSurapong Kanoktipsatharporn on LinkedinSurapong Kanoktipsatharporn on Rss
Surapong Kanoktipsatharporn
Solutions Architect at Bua Labs
The ultimate test of your knowledge is your capacity to convey it to another.

Published by Surapong Kanoktipsatharporn

The ultimate test of your knowledge is your capacity to convey it to another.