ใน ep นี้เราจะมาเรียนรู้ หนึ่งในงาน NLP ภาษาไทย ที่เป็นที่ต้องการมากที่สุด เนื่องจากภาษาไทย เป็นภาษาที่เขียนติดกันหมด ไม่มีการเว้นคำด้วย Space เหมือนภาษาอังกฤษ ทำให้การตัดคำภาษาไทย หรือ Tokenization มีความซับซ้อน และ การตัดคำที่ถูกต้องมีความสำคัญ ต่อการนำข้อมูลคำศัพท์ ไปประมวลผลต่อ เช่น Feed เข้าโมเดล Machine Learning, Deep Learning ต่อไป

ตัวอย่างการตัดคำภาษาไทย

 'จัง|หวัด|เชียง|ราย|ตั้ง|อยู่|ตอน|เหนือ|สุด|ของ|ประ|เทศ|ไทย|',
 'จังหวัด|เชียง|ราย|ตั้ง|อยู่|ตอน|เหนือ|สุด|ของ|ประ|เทศ|ไทย|',
 'จังหวัด|เชียงราย|ตั้งอยู่|ตอน|เหนือ|สุด|ของ|ประ|เทศ|ไทย|',
 'จังหวัด|เชียงราย|ตั้ง|อยู่|ตอนเหนือ|สุด|ของ|ประ|เทศ|ไทย|',
 'จังหวัด|เชียง|ราย|ตั้ง|อยู่|ตอน|เหนือ|สุด|ของ|ประเทศ|ไทย|',
 'จัง|หวัด|เชียงราย|ตั้งอยู่|ตอน|เหนือ|สุด|ของ|ประเทศ|ไทย|',
 'จัง|หวัด|เชียงราย|ตั้ง|อยู่|ตอนเหนือ|สุด|ของ|ประเทศ|ไทย|',
 'จัง|หวัด|เชียงราย|ตั้งอยู่|ตอนเหนือ|สุด|ของ|ประเทศ|ไทย|',
 'จังหวัด|เชียงราย|ตั้งอยู่|ตอนเหนือ|สุด|ของ|ประเทศ|ไทย|'

PyThaiNLP ฟังก์ชัน word_tokenize

API ฟังก์ชันตัดคำของ PyThaiNLP ถูกออกแบบมาให้รองรับการตัดคำ Word, Sentence หลายอัลกอริทึม เช่น

  • newmm – Dictionary-based Thai Word Segmentation using maximal matching algorithm and Thai Character Cluster (TCC). The code is based on the notebooks created by Korakot Chaovavanich.
  • longest – Dictionary-based longest-matching Thai word segmentation. Implementation based on the code from Patorn Utenpattanun.
  • multi_cut – Multi cut – Thai word segmentation with maximum matching. The original source code is from Korakot Chaovavanich.
  • pyicu – Wrapper for PyICU word segmentation. This wrapper module uses icu.BreakIterator with Thai as icu.Local to locate boundaries between words from the text.
  • deepcut – Wrapper for deepcut Thai word segmentation. deepcut is a Thai word segmentation library using Deep Neural, specifically, 1D Convolution Neural Network.
  • attacut – Wrapper for AttaCut – Fast and Reasonably Accurate Word Tokenizer for Thai by Pattarawat Chormai
  • tcc – The implementation of tokenizer according to Thai Character Clusters (TCCs) rules purposed by Theeramunkong et al. 2000.
  • etcc – Enhanced Thai Character Cluster (ETCC) Python implementation by Wannaphong Phatthiyaphaibun (19 June 2017)

โดยอัลกอริทึมใหม่ล่าสุด และเป็น Default ของ PyThaiNLP tokenize ณ ขณะนี้ คือ newmm ที่ใช้ อัลกอริทึม หา maximum matching จากใน Dictionary ที่ทำงานได้อย่างรวดเร็ว และถูกต้อง

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

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.