Skip to main content

KordAI Word Segmentation

ไลบรารีสำหรับตัดคำภาษาไทยจาก Python ใช้งานได้ผ่าน API ที่เรียบง่าย และรันโมเดลในเครื่องด้วย NumPy

ติดตั้ง

pip install kordai-word-segmentation

ต้องใช้ Python 3.10 ขึ้นไป ระบบจะติดตั้ง NumPy ซึ่งเป็น dependency ที่จำเป็นให้อัตโนมัติ ไม่จำเป็นต้องติดตั้ง PyTorch, Transformers หรือ ONNX Runtime เพื่อใช้งาน tokenizer

เริ่มต้นใช้งาน

from kordai_word_segmentation import get_tokenizer

tokenizer = get_tokenizer()

words = tokenizer("ฉันกินข้าวแล้ว")
print(words)

tokenizer จะคืนรายการคำในรูปแบบ list[str] ตัวอย่างผลลัพธ์อาจมีหน้าตาประมาณนี้ โดยผลจริงขึ้นอยู่กับโมเดลเวอร์ชันที่ใช้งาน:

["ฉัน", "กิน", "ข้าว", "แล้ว"]

ตัดคำหลายข้อความ

ส่งข้อความหลายข้อความเป็น arguments ได้โดยตรง:

results = tokenizer(
    "ภาษาไทย",
    "แมวแมว",
    "วันนี้อากาศดี",
)

หรือส่งเป็น list หรือ tuple:

texts = ["ภาษาไทย", "แมวแมว", "วันนี้อากาศดี"]
results = tokenizer(texts)

ทั้งสองวิธีคืนค่าเป็น list[list[str]] โดยผลลัพธ์แต่ละรายการจะตรงกับข้อความ input ตามลำดับ

รูปแบบ input และ output

การเรียกใช้งาน ผลลัพธ์
tokenizer("ภาษาไทย") list[str] — รายการคำของข้อความเดียว
tokenizer("ภาษาไทย", "แมวแมว") list[list[str]] — ผลของแต่ละข้อความ
tokenizer(["ภาษาไทย", "แมวแมว"]) list[list[str]] — ผลของแต่ละข้อความ

ปรับเกณฑ์การตัดคำ

สามารถส่ง threshold ในการเรียกแต่ละครั้งได้ ค่าเริ่มต้นคือ 0.5:

words = tokenizer("ฉันกินข้าวแล้ว", threshold=0.6)

ค่า threshold ต้องอยู่ระหว่าง 0 ถึง 1 การปรับค่านี้อาจเปลี่ยนผลการตัดคำ ควรทดลองกับข้อความที่ตรงกับลักษณะการใช้งานของคุณ

หากต้องการกำหนดค่าเริ่มต้นสำหรับ tokenizer ให้ระบุตอนเรียก get_tokenizer():

tokenizer = get_tokenizer(threshold=0.5, max_len=512)
  • threshold: เกณฑ์เริ่มต้นสำหรับการตัดคำ ค่าเริ่มต้นคือ 0.5
  • max_len: จำนวนตัวอักษรสูงสุดที่ประมวลผลต่อหนึ่งส่วน ต้องไม่เกินความยาวสูงสุดที่โมเดลรองรับ หากไม่ระบุจะใช้ค่าจากโมเดล

สิ่งที่ควรรู้

  • ประมวลผลในเครื่อง: หลังติดตั้งแพ็กเกจแล้ว การตัดคำไม่ต้องส่งข้อความไปยัง API ภายนอกหรือใช้อินเทอร์เน็ต
  • โหลดโมเดลซ้ำให้น้อยที่สุด: get_tokenizer() ใช้ tokenizer instance เดิมในการเรียกครั้งถัดไปภายใน process เดียวกัน
  • ข้อความยาว: ข้อความที่ยาวเกิน max_len จะถูกแบ่งประมวลผลเป็นส่วน ๆ ผลบริเวณรอยต่อของส่วนอาจแตกต่างจากการประมวลผลเป็น sequence เดียว
  • อักขระที่ไม่อยู่ใน vocabulary: หากข้อความมีอักขระที่โมเดลไม่รู้จัก ผลลัพธ์อาจขึ้นอยู่กับการตั้งค่า unknown-token ของโมเดล
  • ความถูกต้อง: ผลลัพธ์ขึ้นอยู่กับโมเดลและข้อความที่ป้อน ควรตรวจสอบกับข้อมูลของงานจริงก่อนใช้งานในระบบสำคัญ

API

  • get_tokenizer() — สร้างหรือรับ tokenizer ที่นำกลับมาใช้ซ้ำได้
  • tokenizer(text) — ตัดคำหนึ่งข้อความและคืน list[str]
  • tokenizer(text1, text2, ...) — ตัดคำหลายข้อความและคืน list[list[str]]
  • tokenizer([text1, text2, ...]) — ตัดคำจากรายการข้อความและคืน list[list[str]]

Metadata

Release files for kordai-word-segmentation 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kordai-word-segmentation 0.1.0
File Size Uploaded Provenance
kordai_word_segmentation-0.1.0.tar.gz 221.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kordai-word-segmentation 0.1.0
File Interpreter ABI Platform
kordai_word_segmentation-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 442.5 kB

Release files / kordai_word_segmentation-0.1.0.tar.gz

Download URL kordai_word_segmentation-0.1.0.tar.gz
Size 221.2 kB
Tags Source
SHA-256 checksum
How to use checksums
767bab5c3f108333975b84ebd0aa5f75f7f2ddd7447b9dd06197c97221e268b5
BLAKE2b-256 checksum
How to use checksums
322309d9170f41758c362c674a89704563fe775cfd99e2c8c5567186204bf79e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / kordai_word_segmentation-0.1.0-py3-none-any.whl

Download URL kordai_word_segmentation-0.1.0-py3-none-any.whl
Size 221.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2db6a9ab9985bef9d8111a4c2ce58d381a1fa252cbeb57d6189940e7e43b5941
BLAKE2b-256 checksum
How to use checksums
4405d7f343bbe9e2ef625e815912c7076eab5703c4f10f119b1a71b7819732e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Security for kordai-word-segmentation 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page