Update Peter Norvig's spell checker to suggest words based on probability#137
Merged
wannaphong merged 19 commits intoPyThaiNLP:devfrom Oct 29, 2018
bact:dev
Merged
Update Peter Norvig's spell checker to suggest words based on probability#137wannaphong merged 19 commits intoPyThaiNLP:devfrom bact:dev
wannaphong merged 19 commits intoPyThaiNLP:devfrom
bact:dev
Conversation
Update documents
Update from PyThaiNLP origin
… on probability (as suggested in issue #90 ) - use word frequencies from Thai National Corpus
wannaphong
approved these changes
Oct 25, 2018
Update from PyThaiNLP/pythainlp
… list for spell checker
wannaphong
reviewed
Oct 26, 2018
pythainlp/spell/pn.py
Outdated
| _WORDS_TOTAL = sum(_WORDS.values()) | ||
|
|
||
|
|
||
| def _prob(word, n=_WORDS_TOTAL): |
Member
There was a problem hiding this comment.
ฟังก์ชันนี้จะเก็บไว้ไหมครับ ?
Member
Author
There was a problem hiding this comment.
ต้องใช้ _prob() สำหรับเป็น sort key ใน correction() ครับ ต้องเก็บไว้ครับ
Member
|
ผมกด Merge ได้เลยไหมครับ @bact |
Member
Author
|
@wannaphongcom ถ้ารีวิวแล้วโอเค merge ได้เลยครับ ผมเพิ่มคลาส |
…ect, based on NorvigSpellChecker class
wannaphong
approved these changes
Oct 29, 2018
Member
Author
|
ขอบคุณครับ :) |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ใช้วิธีดึง (คำ, ความถี่) มาจาก Thai National Corpus (TNC) เพื่อสร้างรายการคำสำหรับคำนวณความน่าจะเป็น
คำ "สะกดผิด" ใน TNC และวิธีแก้ไข
เนื่องจาก TNC มีขนาดใหญ่มาก จึงมีคำที่อาจไม่ได้เป็นคำที่พบทั่วไป หรือใช้ตัวสะกดตามพจนานุกรม
วิธีหนึ่ง (1) ที่เป็นไปได้เพื่อแก้ไขปัญหา คือเอารายการคำจาก TNC มาเทียบกับรายการคำที่เรามั่นใจว่าสะกดถูกแน่ๆ แล้วดึงมาเฉพาะคำที่มีอยู่ในทั้ง 2 รายการ แต่ก็จะทำให้จำนวนคำที่ได้น้อยลง (เป็นไปได้ว่า precision จะสูงขึ้น แต่ recall จะต่ำลง)
อีกวิธี (2) คือ ไปใช้ Thai Textbook Corpus (TTC) แทน ซึ่งจะเป็นคำที่เป็นทางการกว่า
วิธีที่ใช้ในปัจจุบัน (3) คือ ใช้ TNC ตามที่ดึงมาได้ แล้วกรองเอาคำจำนวนหนึ่งออกไป เพื่อให้มีเฉพาะคำที่น่าจะเป็นประโยชน์ต่อการแก้ไขคำผิด
วิธีที่ (3) นี้ จากการดูด้วยตาคร่าวๆ พบว่าคำที่มีความถี่เท่ากับ 2 มีทั้งคำที่สะกดผิดและถูก แต่โดยรวมแล้วคุณภาพน่าจะใช้ได้ โดยคาดหวังว่าคำที่สะกดถูกที่มี edit distance เดียวกันจะมีความถี่มากกว่า ทำให้ปัญหาไม่น่าจะมีมากนัก
ตัวอย่างคำและความถี่ที่พบใน TNC:
๒๕๔๘ 452
๑๕๐ 441
๒๕๔๗ 372
_______________________________ 48
วิทยาศาสตร์เทคโนโลยีและสิ่งแวดล้อม 10
งงงงงงงงงงงงงงงงงงงงงง 2
ม่อต้อ 2
ตลกหัวเราะ 2
เทรอซ์ 2
ยุกติธรรม 2
โหรสพ 2
ยยยยยยยยยยยยยยย 2
ปากขม 2
เจริญสมณธรรม 2
ลองเพลย์ 2
เตตียม 2
นั่งทางใน 2
ลิคเตนสไตน์ 2
มวยหมู่ 2
ข้าวนก 2
กะบ่อนกะแบ่น 2
เสิรฟ์ 2
66-70-73 2
Directors 2
.สำหรับชาวไทยมุสลิมในสี่จังหวัดภาคใต้ซึ่งยิ่งด้อยการศึกษาเป็นส่วนมากไม่ใช่เป็นเรื่องง่าย 1
.ได้ชี้แจงกับกลุ่มการเมืองว่าช่วงเวลา 1
.ต.ท.ทักษิณและให้การต้อนรับรัฐบาลของตนถึงสองครั้งสองคราทำไมการเดินทางของ 1