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, named entity recognition (NER), 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"}, ...]

# Named entity recognition
nlp.ner("គ្រូពេទ្យធ្វើការនៅមន្ទីរពេទ្យភ្នំពេញ")
# → [{"text": "ភ្នំពេញ", "label": "LOC"}]

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

# 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
ner(text) list[dict] Named entities (PER, LOC)
polarity(text) dict Sentiment polarity
analyze(text) dict All tasks combined

Raw token-level outputs: seg_tokens(), pos_tokens(), ner_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.0.tar.gz (9.3 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.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: khmer_nlp_kcc-0.2.0.tar.gz
  • Upload date:
  • Size: 9.3 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.0.tar.gz
Algorithm Hash digest
SHA256 06a64506f1ae5945b9deed1530d20cd0611e6f67ae0e0d72fde737057fa92afd
MD5 3ba88fdf60d531e610e00afd37adbca9
BLAKE2b-256 d942266e269a63e5a4767b6222788fe7a0e1429709657aa5b3aa44e3a61066dd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: khmer_nlp_kcc-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4889cfde989884307630269e71df4041207546ebbfceaaf17f8c4f0fa7e888fc
MD5 950ad5e3d5a4eec68dda764657849a36
BLAKE2b-256 9208d974fbfd6054e546fd362a7478bb103ad437c4f7956227b711f4624c7409

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