Skip to main content

Neam (នាម)

Khmer named entity recognition for news. Neam finds people (PER), organizations (ORG) and places (LOC) in Khmer text and returns exact character offsets in your original input. It runs offline on a CPU.

នាម means "name, noun": the named in named entity.

Exact-span F1
Held-out Khmer news (10 articles, 199 entities) 84.2
Validation Khmer news (5 articles, 108 entities) 78.0

An entity counts only if both its boundaries and its type are exact. Retraining with different seeds gives about 82–83 on average. See MODEL_CARD.md for the details and limitations.

Install

pip install neam            # library
pip install "neam[app]"     # plus the web app

Python 3.10+. Install the PyTorch build that suits your machine first if you want GPU support. The model (about 113 MB) downloads from the Hugging Face Hub on first use.

To work on the code itself, clone the repository and run pip install -e ".[app]".

Use

from neam import Neam

ner = Neam.from_pretrained("MoriartyPuth/neam")   # or a local model folder
result = ner.predict("លោក ហ៊ុន ម៉ាណែត បានជួបជាមួយក្រសួងសុខាភិបាលនៅរាជធានីភ្នំពេញ។")
for entity in result["entities"]:
    print(entity["label"], entity["text"], entity["start"], entity["end"])
# PER លោក ហ៊ុន ម៉ាណែត 0 15
# ORG ក្រសួងសុខាភិបាល 27 42
# LOC រាជធានីភ្នំពេញ 44 58

From the command line:

python -m neam.inference --text "ក្រសួងអប់រំ យុវជន និងកីឡា បានប្រកាសលទ្ធផលថ្មី។"

Each entity has label, text, start, end (Python character offsets into the input) and score, the model's mean confidence, which is not a calibrated probability.

Web app

The web app is app.py in this repository. Run it from a clone after pip install -e ".[app]":

python app.py                      # http://127.0.0.1:7860
python app.py --model /path/to/local/model

Paste Khmer text, or open Import an online article and give a public news URL. The page is fetched with redirect and private-network checks, and the text is limited to 20,000 characters. Highlights: PER red, ORG green, LOC blue.

How it works

  1. Segmentation. Text is split into words with khmer-nltk. Only zero-width characters (U+200B/C/D) are dropped; offsets always point into the original string.
  2. Subword alignment. Each word's label is read from its first subword that is not a bare SentencePiece ▁ marker.
  3. Overlapping windows. Long texts are read in 128-subword windows that overlap. Each word is taken from the window where it has the most context on both sides.
  4. Ensemble and Viterbi. Three ALBERT models' probabilities are averaged and decoded into the best valid IOB2 sequence.
  5. Display rules. Short honorifics (លោក) join a following name, place designators (ខេត្ត, ស្រុក, …) are completed, nationality phrases (ជនជាតិ + country) are not tagged as places, and sentence punctuation is trimmed.

The labelling rules are in docs/annotation_policy.md.

Development

python -m unittest discover -s tests

scripts/export_model.py packages a trained ensemble folder into the Hub layout (ensemble.json plus members/). Training code and research history are kept in a separate research repository.

License

Apache-2.0. See LICENSE and NOTICE for third-party attributions.

Metadata

Release files for neam 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 neam 0.1.0
File Size Uploaded Provenance
neam-0.1.0.tar.gz 26.1 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 46.8 kB

Release files / neam-0.1.0.tar.gz

Download URL neam-0.1.0.tar.gz
Size 26.1 kB
Tags Source
SHA-256 checksum
How to use checksums
748862d3e83a36c8295fd751c9b456240490ecdadd9a0e7af3127ce11cad11ab
BLAKE2b-256 checksum
How to use checksums
9bc898c2e2bc737681811bac0460e947e9f095691029c027f30379f11295de80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

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

Download URL neam-0.1.0-py3-none-any.whl
Size 20.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
939231b2c6b224d2f2ade49531de22a5dae6355d4f309bba7e91dd7ebc1cc6e5
BLAKE2b-256 checksum
How to use checksums
25fae9dc1ce9960aa259f3cbdcba50a5398a4a92f704ce10468aab2cb7db33fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for neam 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.

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