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"}, {"word": "ញាំបាយ", "label": "VB"}]

# Named entity recognition
nlp.ner("លោក សុខ សុភ័ក្រ្ត ធ្វើការនៅភ្នំពេញ")
# → [{"text": "សុខសុភ័ក្រ្ត", "label": "PER"}]

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: khmer_nlp_kcc-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 fc06676a14e36ed9cb033748ec19a720c673e4f4f0f6f187d5dcbcebfe9db28d
MD5 1d3881928458bb6b795e2b9268a08b85
BLAKE2b-256 2b626b385cfa0150b2646dab53a76bd08f313eb1f044e2c462f9f0feadbfbd4c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: khmer_nlp_kcc-0.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2596c1b4c8af3a91d00e3b6266471dcc79df2e7876c0e88c4dd4a1b84b22f476
MD5 c0c33161f597355f46f5686757458880
BLAKE2b-256 9af18cbf00ff3d5daae4b39ad4db9a67f979c93783eb0b1cba6cf6432486497a

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