Skip to main content

Khmer Keyboard Prediction Engine

Project description

Khmer Keyboard Prediction Engine

Khmer keyboard prediction engine for offline/mobile usage.

It supports:

  • Next-word prediction (trigram with bigram/unigram fallback)
  • Prefix suggestion
  • Typo correction
  • Smart auto mode (smart) that decides how to respond from user input

Install

From PyPI:

pip install khmer-keyboard

From local source:

pip install -U .

Package Structure

khmer_keyboard/
  train/
    build_lm.py
    build_chargram.py
    export_model.py
  runtime/
    language_model.py
    chargram_embedder.py
    scorer.py
    personalization.py
    engine.py
  model.msgpack

Quick Start

from khmer_keyboard import KhmerKeyboardEngine

# Uses bundled khmer_keyboard/model.msgpack
engine = KhmerKeyboardEngine()

Core APIs

# Prefix suggestion
engine.suggest_prefix("ស", top_n=5)
# ["សូម", "សម្រាប់", "សួស្តី", "សកម្ម", "សាលា"]

# Typo correction
engine.correct_word("កមពជ", top_n=5)
# ["កម្ពុជ", "កម្ពុជា", "កុម្ពុជ", "កម្ពជ", "កពជ"]

# Next-word prediction from context
engine.predict_next("ខ្ញុំ", "ចង់", top_n=5)
# ["ទៅ", "ធ្វើ", "រៀន", "បាន", "សួរ"]

Smart API (Recommended)

smart(...) is the main user-facing API.
It auto-selects behavior:

  • If input ends with space: next-word prediction
  • If input is partial token: prefix suggestion
  • If token looks wrong: typo correction
  • If no-space merged phrase is detected: attempts phrase split, then next-word prediction
  • If no strong match: safe fallback (never empty list)

Examples:

engine.smart("ខ្ញុំ ចង់ ")   # next-word mode
engine.smart("ស")            # prefix mode
engine.smart("សរឡញ")         # correction/suggestion mode
engine.smart("ខញសរឡញ")       # merged phrase recovery mode

Example Output (Format)

Output is always list[str]:

['ទៅ', 'ធ្វើ', 'ញុំា', 'បាន', 'រៀន']
['សួស្តី', 'សម្រាប់', 'សូម', 'សកម្ម', 'សាលា']

Exact words depend on your trained model and corpus quality.

Use External Model

engine = KhmerKeyboardEngine(model_path="path/to/model.msgpack")

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_keyboard-0.1.2.tar.gz (21.2 MB view details)

Uploaded Source

Built Distribution

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

khmer_keyboard-0.1.2-py3-none-any.whl (21.6 MB view details)

Uploaded Python 3

File details

Details for the file khmer_keyboard-0.1.2.tar.gz.

File metadata

  • Download URL: khmer_keyboard-0.1.2.tar.gz
  • Upload date:
  • Size: 21.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for khmer_keyboard-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d87f514ede7947ca88dc95d9bd35cfd203ff3ea8b36d050518dc862db4c8624d
MD5 09f72c64973ecfe5fc29652f938b4946
BLAKE2b-256 6c6306082403e2bab0a9e2a4dc715e04af3633a626e32efae7ef9276a24cc9aa

See more details on using hashes here.

File details

Details for the file khmer_keyboard-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: khmer_keyboard-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 21.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for khmer_keyboard-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f91413a342b1c2a39b4205f038642898c6b70842cdfc2d74b30116997808ffd1
MD5 e7223977880b29ed15837ab637bbf7e6
BLAKE2b-256 e5b760baa2b148e86639a3f3cdb08272743dc5388fea65036c024e86f8b5ec8a

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