Skip to main content

Khmer word segmentation, POS tagging, NER, and more — powered by a custom Khmer language model

Project description

khmer-nlp-kcc

Khmer NLP toolkit — word segmentation, POS tagging, and sentiment polarity.

Powered by a custom Khmer language model. The checkpoint is downloaded automatically from HuggingFace Hub on first use.

Installation

pip install khmer-nlp-kcc

Quick start

from khmer_nlp import KhmerNLP

nlp = KhmerNLP()  # checkpoint downloads on first call

# Word segmentation
nlp.segment("គាត់ចូលចិត្តអានសៀវភៅ")
# → ["គាត់", "ចូលចិត្ត", "អាន", "សៀវភៅ"]

# POS tagging
nlp.pos("គាត់ចូលចិត្តអានសៀវភៅ")
# → [{"word": "គាត់", "label": "PRO"}, {"word": "ចូលចិត្ត", "label": "VB"}, {"word": "អាន", "label": "VB"}, {"word": "សៀវភៅ", "label": "NN"}]

# Sentiment polarity
nlp.polarity("ខ្ញុំចូលចិត្តប្រទេសខ្មែរណាស់")
# → {"label": "positive", "confidence": 0.9944, "scores": {"negative": 0.0023, "neutral": 0.0032, "positive": 0.9944}}

# All tasks at once
nlp.analyze("គាត់ចូលចិត្តអានសៀវភៅ")

Custom checkpoint

nlp = KhmerNLP(checkpoint_path="/path/to/your/model.pt")

Device selection

import torch
nlp = KhmerNLP(device=torch.device("cuda:0"))

Available methods

Method Returns Description
segment(text) list[str] Segmented word list
pos(text) list[dict] Word + POS label
polarity(text) dict Sentiment polarity
analyze(text) dict All tasks combined

Raw token-level outputs: seg_tokens(), pos_tokens().

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

khmer_nlp_kcc-0.2.4.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

khmer_nlp_kcc-0.2.4-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file khmer_nlp_kcc-0.2.4.tar.gz.

File metadata

  • Download URL: khmer_nlp_kcc-0.2.4.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for khmer_nlp_kcc-0.2.4.tar.gz
Algorithm Hash digest
SHA256 02b243d9f670dc25a0fb2c3ec48f68d66ef874b5ba7516d475d00296b4ad5c23
MD5 c3a1b34fef4a2415ac66edc7c19cd8ab
BLAKE2b-256 662390f51a3fe2b0a48d667c2936e38e0981a501e3457051a58ec93595b83893

See more details on using hashes here.

File details

Details for the file khmer_nlp_kcc-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: khmer_nlp_kcc-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for khmer_nlp_kcc-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cfb8eab4bc6a339e92db51a553d21d117cd061e8289769b470e6be43e038cef1
MD5 ffe7b921523cf063c64ff533633717c1
BLAKE2b-256 02cafc6626ec80a1b26de41ff08cbaefc835becde15fc3221308a37ea714e8ff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page