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.1.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.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: khmer_nlp_kcc-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 54badad6a089426dd5af23ba438f8b340ebd63dc3c18981f2e93a869bfdb25ee
MD5 5976f620a7171fef4fcc77aecfcdf82f
BLAKE2b-256 470933eb31b6895f88f67edc6a53ebad8c62be0c3aa7908157d3dba16e25eb18

See more details on using hashes here.

File details

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

File metadata

  • Download URL: khmer_nlp_kcc-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 de43323d630135345e343fe333a92d073130e20390421d1eb5afd69c04d7efae
MD5 b47abcdf496997b0c7f1788e7691777e
BLAKE2b-256 81238c2752dee20adf736351fd38fa446fedcdc08fe42a6c4a56cc351c4bbef0

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