pythainlp icon indicating copy to clipboard operation
pythainlp copied to clipboard

Newmm-safe is inconsistence

Open chameleonTK opened this issue 3 years ago • 3 comments

I tried newmm-safe engine but it gave inconsistent results. It sometimes tokenized correctly but sometimes not.

Description

Example: "ในฐานข้อมูลกฎหมายของเว็บไซต์ ทส. ข้อมูลและทรัพยากร ข้อมูลกฎหมายว่าด้วยป่าชุมชน CSV downloads กฎหมายแม่บท และกฎหมายลำดับรอง ของพระราชบัญญัติป่าชุมชน พ.ศ. 2562..."

It can correctly tokenize "ข้อมูลกฎหมายว่าด้วยป่าชุมชน" into ['ข้อมูล', 'กฎหมาย', 'ว่าด้วย', 'ป่าชุมชน']

If I changed the input into "ในฐานข้อมูลกฎหมายของเว็บไซต์ ทส. ข้อมูลและทรัพยากร ข้อมูลกฎหมายว่าด้วยป่าชุมชน CSV downloads กฎหมายแม่บท และกฎหมายลำดับรอง ของพระราชบัญญัติป่าชุมชน พ.ศ. 2562... สำรวจ"

It tokenizes "ข้อมูลกฎหมายว่าด้วยป่าชุมชน" into ['ข้อมูล', 'กฎ', 'หม', 'าย', 'ว่าด้วย', 'ป่าชุมชน']

Expected results

It should produce the same results for both inputs.

Steps to reproduce

from pythainlp.tokenize import word_tokenize
docs = '''ในฐานข้อมูลกฎหมายของเว็บไซต์ ทส. ข้อมูลและทรัพยากร ข้อมูลกฎหมายว่าด้วยป่าชุมชน CSV downloads กฎหมายแม่บท และกฎหมายลำดับรอง ของพระราชบัญญัติป่าชุมชน พ.ศ. 2562... สำรวจ
'''
words = word_tokenize(docs, engine="newmm-safe", keep_whitespace=False)

print(words)

Your environment

  • PyThaiNLP version: 3.1.0
  • Python version: 3.9.7
  • Operating system and version: MacOS

chameleonTK avatar Nov 02 '22 05:11 chameleonTK

Hello @chameleonTK, thank you for your interest in our work!

If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

github-actions[bot] avatar Nov 02 '22 05:11 github-actions[bot]

https://github.com/PyThaiNLP/pythainlp/blob/dev/pythainlp/tokenize/newmm.py#L193

Adding _TEXT_SCAN_BEGIN to cut_pos could help. cut_pos = space_idx + 1 + _TEXT_SCAN_BEGIN

tongplw avatar Aug 16 '23 10:08 tongplw

Thx @chameleonTK for reporting and @tongplw for pointing out possible solution. Let me take a look at this closely.

bact avatar Aug 18 '23 16:08 bact