Skip to main content

Arabic text diacritization (dotting) library: restoring dots to undotted Arabic Rasm.

Project description

tnqeet

tnqeet is an Arabic dots restoration (dotting) library. It restores dots to dotless Arabic text (Rasm), where several letters collapse to the same basic shape once their dots are removed — for example ب ت ث all share one dotless form. Restoring the dots requires resolving this ambiguity from context.

For instance, the dotted sentence:

لسان الفتى شطر وشطر فؤاده

has the dotless (Rasm) form:

لساں الڡٮى سطر وسطر ڡواده

and the dotting task is to recover the former from the latter.

The library implements and evaluates several approaches to dotting: sequence-labeling (BiLSTM), Transformer, CANINE, n-gram language models (KenLM), and LLM-based models.

Installation

pip install tnqeet

This installs everything needed for the neural dotters (BiLSTM, Transformer, CANINE). The n-gram method additionally requires KenLM, which is not installed automatically because it compiles from source — see N-gram method (KenLM).

Usage

Remove dots

Convert dotted Arabic text to its dotless Rasm form:

from tnqeet import remove_dots

remove_dots("لسان الفتى شطر وشطر فؤاده")
# -> "لساں الڡٮى سطر وسطر ڡواده"

Restore dots

Load a pretrained model and restore the dots. Weights are downloaded from the Hugging Face Hub on first use and cached locally:

from tnqeet.dotting_models.transformer.models import TransformerDottingModel

model = TransformerDottingModel.from_pretrained()  # default size (6L)

model.restore_dots("لساں الڡٮى سطر وسطر ڡواده")
# -> "لسان الفتى شطر وشطر فؤاده"

restore_dots accepts a single string (returns a string) or a list of strings (returns a list).

Available models

Each method exposes from_pretrained(size) with friendly size keys (the default is used when no size is given):

Method Class Sizes (default in bold)
BiLSTM LSTMDottingModel 1L6L (4L)
Transformer TransformerDottingModel 3L, 6L, 9L, 12L
CANINE CanineDottingModel c, s
n-gram NgramDotter order 28 (6)
from tnqeet.dotting_models.canine.models import CanineDottingModel

model = CanineDottingModel.from_pretrained("c")   # pick a specific size

The three neural models are PyTorch modules; move them to a GPU with the usual .to("cuda") and switch to eval mode with .eval() for inference.

N-gram method (KenLM)

The n-gram dotter is backed by KenLM, which compiles from source and is therefore not a dependency of tnqeet. Install it yourself, setting MAX_ORDER to at least the highest n-gram order you intend to load. tnqeet publishes orders up to 8, so build with MAX_ORDER=8 (KenLM's own default is 6, which cannot load orders 7–8):

MAX_ORDER=8 pip install "git+https://github.com/kpu/kenlm.git"

Then:

from tnqeet.dotting_models.ngrams.models import NgramDotter

dotter = NgramDotter.from_pretrained(order=6, beam_size=10)

dotter.restore_dots("لساں الڡٮى سطر وسطر ڡواده")
# -> "لسان الفتى شطر وشطر فؤاده"

Calling NgramDotter.from_pretrained(...) without KenLM installed raises an ImportError containing the install command above.

See CLAUDE.md for the full inference APIs and project layout.

Development

The project uses uv for dependency management and packaging. Clone the repository and set up the environment:

git clone https://github.com/MagedSaeed/tnqeet
cd tnqeet
uv sync   # installs the project plus the dev dependency group

uv sync installs everything needed to train, evaluate, and run the notebooks — including KenLM (built from source via MAX_ORDER, double check its installation) and the training/visualization tools (wandb, matplotlib, seaborn, ipython) that the published package omits. To build KenLM for a higher order, set MAX_ORDER before syncing:

MAX_ORDER=8 uv sync

Run the quality checks and tests:

uv run isort --check .
uv run black --check .
uv run ruff check .
uv run mypy .
uv run pytest

Building and publishing is handled by CI on a version tag (see .github/workflows/publish.yml); to build locally:

uv build

License

Apache-2.0. See LICENSE.

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

tnqeet-0.1.2.tar.gz (310.3 kB view details)

Uploaded Source

Built Distribution

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

tnqeet-0.1.2-py3-none-any.whl (64.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tnqeet-0.1.2.tar.gz
  • Upload date:
  • Size: 310.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tnqeet-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6171eb9d1a0889c1ecdb8d36b3ee7c0f40ad7cad0b6ca0c58eee20449727ba79
MD5 11e18cc2fe8cf7a64a13198a8d8fadab
BLAKE2b-256 c0cf50e9cf9b4f994c6a82d66aa0b446d6ae69f0a54ee23e8a5d28935248c1f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tnqeet-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 64.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tnqeet-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0b905b05b82bd4967da0fa47736fff9e21e81cac6303a6c0d83e189f72d97978
MD5 71f2d7a5c25c111d9c2ae9c8f58aba5d
BLAKE2b-256 d91cab10e2bed1dc2aea68e91b344d9a9d4619e09af79af4e7f56e2f4e7589a9

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