Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pythainlp.word_tokenize ปัญหาตัดคำประโยคที่ยาวต่อเนื่องโดยไม่มี space [newmm] #241

Closed
espressofx opened this issue Jul 26, 2019 · 7 comments · Fixed by #333
Assignees
Labels
bug bugs in the library
Milestone

Comments

@espressofx
Copy link

Describe the bug
มีปัญหา execute ใช้เวลานานมาก กับประโยคที่ยาวต่อเนื่องโดยไม่มี space แบ่ง
เช่น ประโยค

ด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้า

แต่ถ้ามีการแบ่งประโยคโดยมี space จะไม่มีปัญหา เช่น

ด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้า ด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้า ด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้า ด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้า ด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้า ด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้า ด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้า ด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้า ด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้าด้านหน้า

Desktop (please complete the following information):

  • OS: ubuntu 18.04
  • Python 3.6
  • Pythainlp 2.0.5
@espressofx
Copy link
Author

จาก notebook ต้อง interrupt kernel

Screenshot from 2019-07-26 17-17-46

@wannaphong wannaphong added the bug bugs in the library label Jul 26, 2019
@bact
Copy link
Member

bact commented Sep 11, 2019

May need some rule to stop generating word graphs when reaching a threshold.

คิดว่าในโค้ดที่พยายามสร้างทางที่เป็นไปได้ที่จะตัดคำ น่าจะต้องมีกำหนดไว้ ว่าจะทำถึงแค่ไหน เกินนี้จะบังคับหยุด ไม่งั้นมันจะสร้างไปเรื่อยๆ จนช้ามากๆ

@wannaphong
Copy link
Member

@bact bact added this to the 2.1 milestone Oct 5, 2019
@p16i
Copy link
Contributor

p16i commented Oct 6, 2019

I guess this result comes from newmm? Should we label the issue with newmm?

@bact bact self-assigned this Oct 8, 2019
@bact bact changed the title pythainlp.word_tokenize ปัญหาตัดคำประโยคที่ยาวต่อเนื่องโดยไม่มี space pythainlp.word_tokenize ปัญหาตัดคำประโยคที่ยาวต่อเนื่องโดยไม่มี space [newmm] Oct 8, 2019
@bact
Copy link
Member

bact commented Oct 12, 2019

Proposal for the fix:

  • break the input text into smaller chunks (100±25)
    • chunking strategy should take into account the invalid token separation point (this can be either word or syllable)
  • tokenizes each chunks and combine tokens together

See code in pythainlp/tokenize/newmm.py here #302

Warn that this may make the tokenization slower.

Current chunk size is 100
(Have tried 400, too slow).

Current window to scan possible break points between chunks is 25+25 = 50
(the longest word in dictionary is 70 chars)

Please comment

@bact
Copy link
Member

bact commented Nov 12, 2019

A new segmentation "engine" has been proposed for this, one can now use newmm-safe engine to avoid the problem of waiting too long for text like one in the example above. Now available in fix-newmm-longtext branch and will soon in dev branch.

ต่อไปจะมี engine ใหม่ชื่อ newmm-safe เพื่อแก้ปัญหานี้ครับ

pythainlp.tokenzie.word_tokenize("ด้านหน้าด้านหน้าด้านหน้า", engine="newmm-safe")

@bact
Copy link
Member

bact commented Nov 15, 2019

แก้ไขแล้วนะครับ จะสามารถใช้ได้ในรุ่น 2.1dev8 ครับ

Fixed with #302 - will be available in 2.1dev8 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs in the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants