Skip to main content

ONNX-based Arabic Consecutive-Character Deduplicator (Candle model by Abjad AI)

Project description

candle-deduplicator

License

ONNX-based Arabic consecutive-character deduplication powered by the CANDLE model from Abjad AI.

The model removes unintentional character elongation that appears in user-generated Arabic text — for example:

Input Output
الممملكككة الأررررردنييية الللهههااااششميية المملكة الأردنية الهاشمية
الممملكككة الأررررردنييية ررراااننيييااا الملكة الأردنية رانيا
مررررحبببببا مرحبا

Installation

pip install candle-deduplicator

For GPU inference, uninstall onnxruntime and install the GPU variant instead:

pip uninstall onnxruntime
pip install candle-deduplicator onnxruntime-gpu

ONNX model weights are downloaded automatically on first use and cached inside the package directory.


Quick start

Single string

from candle_deduplicator import CandleDeduplicator

model = CandleDeduplicator()
print(model.deduplicate('الممملكككة الأررررردنييية الللهههااااششميية'))
# المملكة الأردنية الهاشمية

Batch inference

texts = [
    'الممملكككة الأررررردنييية',
    'مررررحبببببا بببالعررربييية',
]
results = model.deduplicate_batch(texts, batch_size=32)
print(results)

Distilled (faster) variant

from candle_deduplicator import CandleDeduplicatorDistilled

model = CandleDeduplicatorDistilled()
print(model.deduplicate('مررررحبببببا'))
# مرحبا

Load a local ONNX file

Pass model_path to skip the auto-download and load directly from disk:

model = CandleDeduplicator(model_path="full_model.onnx")
model = CandleDeduplicatorDistilled(model_path="distilled_model.onnx")

GPU inference

model = CandleDeduplicator(model_path="full_model.onnx", device="cuda")
# ✅ Loaded model successfully! (provider: CUDAExecutionProvider)

If onnxruntime-gpu is not installed or CUDA is unavailable, ONNX Runtime falls back to CPU automatically and the printed provider will reflect that.


API reference

CandleDeduplicator(model_path=None, auto_preprocess=True, device="cpu")

Full 6-layer encoder model. Higher accuracy, recommended for offline batch processing.

CandleDeduplicatorDistilled(model_path=None, auto_preprocess=True, device="cpu")

Distilled 2-layer encoder model. Faster inference, recommended for latency-sensitive applications.

Both classes share the same interface:

Method Description
deduplicate(text) Deduplicate a single string.
deduplicate_batch(texts, batch_size=16, verbose=True) Deduplicate a list of strings.

Constructor parameters

Parameter Type Default Description
model_path str or None None Path to a local .onnx file. When None the model is downloaded automatically from GitHub Releases.
auto_preprocess bool True Strip non-Arabic characters before running the model.
device str "cpu" Execution device: "cpu" or "cuda". GPU requires onnxruntime-gpu.

How it works

The CANDLE model uses an encoder-only Transformer trained with CTC loss. During inference:

  1. Each input string is checked for consecutive duplicate characters. Strings that are already clean skip the model entirely.
  2. Strings with duplicates are normalised to at most two consecutive occurrences of each character and tokenised at the character level.
  3. The encoder produces per-token logits; greedy argmax selects the most likely token at each position.
  4. CTC greedy decoding collapses repeated tokens and removes blank symbols to recover the deduplicated text.
  5. A word-level guard ensures that words without duplicates in the original text are never altered by the model.

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

candle_deduplicator-1.0.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

candle_deduplicator-1.0.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file candle_deduplicator-1.0.0.tar.gz.

File metadata

  • Download URL: candle_deduplicator-1.0.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for candle_deduplicator-1.0.0.tar.gz
Algorithm Hash digest
SHA256 211ffdb8e51bec10dab9dd8310436e5bc423d5131dccbcd551914afb589510c5
MD5 e190165a5a9facb595f399eb0a90143b
BLAKE2b-256 16c54063276382fd0517636399cbaf71a0f5a6652730d38aacdff16986b65490

See more details on using hashes here.

File details

Details for the file candle_deduplicator-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for candle_deduplicator-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0bb3d2bd98fe9f7ec56d8e76538c979f6e1f63d9f0ce23f9f53821b6ee097305
MD5 177dd15f61f665b4664d15c2f20ecb24
BLAKE2b-256 d89b974a1b1e8f21cbcfef94b9c9a0c91df27088366fcae8cc6206f023b94eb9

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