Skip to main content

Sinhala NLP Toolkit

Project description

Sinlib

Sinlib Logo

PyPI version Python Versions License: MIT Docs

A Python toolkit for Sinhala natural language processing — phonological tokenization, spell checking, and text preprocessing.

Note: The Romanizer and Transliterator modules are temporarily unavailable due to a known bug and will be restored in a future release.

Installation

pip install sinlib

Quick Start

Tokenization

from sinlib import Tokenizer

tokenizer = Tokenizer.from_pretrained("Ransaka/sinlib")

# Split into phonological units (base consonant + diacritics)
tokens = tokenizer.tokenize("ආයුබෝවන්")
# ['ආ', 'යු', 'බෝ', 'ව', 'න්']

# Encode to integer IDs
encoding = tokenizer("ආයුබෝවන්")
encoding.input_ids       # [4, 23, 18, 7, 12]
encoding.attention_mask  # [1, 1, 1, 1, 1]

# Batch encode with padding
batch = tokenizer(["ආයුබෝවන්", "සිංහල"], padding=True)
batch.input_ids  # [[4, 23, 18, 7, 12], [9, 31, 6, 0, 0]]

Spell Checking

from sinlib import TypoDetector

detector = TypoDetector.from_pretrained("Ransaka/sinlib")

# Auto-correct a sentence
detector("අපකරියට ගිය")
# 'අපකීර්තියට ගිය'

# Get correction suggestions
detector.suggest_correction("අඩිරාජ")
# ['අධිරාජ']

Preprocessing

from sinlib import preprocessing

# Remove noise and normalise text
clean = preprocessing.process_text("Hello, මේ සිංහල වාක්‍යකි.")

# Compute Sinhala character ratio
ratio = preprocessing.get_sinhala_character_ratio(["මෙය සිංහල වාක්‍යක්"])
# [0.9]

Why phonological tokenization?

Sinhala script combines a base consonant with one or more vowel diacritics into a single phonetic unit. Standard Unicode tokenization breaks these apart, producing incorrect representations for downstream tasks like ASR and TTS.

"ආයුබෝවන්"

Sinlib  →  ['ආ', 'යු', 'බෝ', 'ව', 'න්']   ✓ phonological units
Unicode →  ['ආ', 'ය', 'ු', 'බ', 'ෝ', 'ව', 'න', '්']   ✗ raw code points

Vocab and model weights are fetched automatically from Ransaka/sinlib on HuggingFace Hub at first use — no manual setup required.

Documentation

Full documentation is available at sinlib.readthedocs.io, including:

Contributing

Contributions are welcome. Please open an issue or submit a pull request on GitHub.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-feature)
  3. Commit your changes (git commit -m 'Add my feature')
  4. Push to the branch (git push origin feature/my-feature)
  5. Open a Pull Request

License

MIT License — see the LICENSE file for details.

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

sinlib-0.2.0.tar.gz (5.7 MB view details)

Uploaded Source

Built Distribution

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

sinlib-0.2.0-py3-none-any.whl (5.0 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sinlib-0.2.0.tar.gz
  • Upload date:
  • Size: 5.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for sinlib-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1ea8741c0c3c725ece126e591672a80c31fa0df65589de8b2ffa1f62ed2d19c5
MD5 4a80c95de43b9115f2d55cd151b62e49
BLAKE2b-256 c88b0f957f6de40b4417945c2b10004dcc1acc288502b57df42963daadd24df1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sinlib-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for sinlib-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98509ac4eafe4e6c0e1da0532afe327c41e6c3dddd44d89200e98af1b33e6696
MD5 e945eb5aa76cb5f948a3481f9de57326
BLAKE2b-256 1307604215323be3189cd10311ac2947e5445fb44529e839f764e0e5431588fa

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