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 |
1L–6L (4L) |
| Transformer | TransformerDottingModel |
3L, 6L, 9L, 12L |
| CANINE | CanineDottingModel |
c, s |
| n-gram | NgramDotter |
order 2–8 (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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tnqeet-0.1.1.tar.gz.
File metadata
- Download URL: tnqeet-0.1.1.tar.gz
- Upload date:
- Size: 48.2 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4999bad8547d7e2e896801e81f2d32354f5d81a3841d3ea9fd486590bbba2146
|
|
| MD5 |
2afa2e3ec5727e6576584247e2af01d9
|
|
| BLAKE2b-256 |
8c503713f23f01f173be09d230f4a8693e1c66fe5b7ef7f3d92a85955a729de5
|
File details
Details for the file tnqeet-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tnqeet-0.1.1-py3-none-any.whl
- Upload date:
- Size: 64.9 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48483a6844528e9983b9daecfc03edca0f9baa916224b030ac8761d881eaf2e4
|
|
| MD5 |
8fa0771b9718a220490a6796ac7d94c3
|
|
| BLAKE2b-256 |
4dddea4ca5aa99cd36885792c44317afe26416987b7b96e8894c62f437f28a55
|