sindhinorm Docs
v0.2.0 PyPI GitHub
sindhinorm 0.2.0 fixes only the letters a non-Sindhi keyboard produces and leaves correct Sindhi alone. What's new

sindhinorm documentation

Spelling normalization for Sindhi text typed on Urdu, Persian or Arabic keyboards. It fixes look-alike letters word by word, never merges two real Sindhi words, and leaves correctly typed text alone.

Sindhi text is often typed on keyboards that lack Sindhi letters, so letters that look identical are different characters to software: ی instead of ي, ہ instead of ه, ک or ك instead of ڪ. Search, counting and NLP models then treat one word as several. A fixed character map cannot repair this, because ک and ڪ are both Sindhi letters: کي ("to") and ڪي ("some") are different words.

Install

pip install sindhinorm

Pure Python, no dependencies, Python 3.10 or newer. The package bundles a Sindhi Wikipedia word list (61,718 words) used to choose between spellings.

Quickstart

from sindhinorm import normalize, explain

normalize("هي ڪتاب آهی")   # 'هي ڪتاب آهي'  (Farsi yeh fixed)
normalize("ڪي کي")          # 'ڪي کي'        (two different words: left alone)

explain("ہن آهی کري")
# [{'word': 'ہن', 'output': 'هن', 'rule': 'encoding-merge', 'count_in': 0, 'count_out': 22047},
#  {'word': 'آهی', 'output': 'آهي', 'rule': 'encoding-merge', 'count_in': 0, 'count_out': 62425},
#  {'word': 'کري', 'output': 'کري', 'rule': 'native-keep', 'count_in': 14, 'count_out': 14}]

Playground

Paste Sindhi text, or press Scramble keyboard to retype the example as an Urdu keyboard would. Everything runs in your browser with the same rules as the Python package; nothing you type is sent anywhere.

Normalized

Blue: a keyboard letter replaced. Red: a different Sindhi letter (ک → ڪ). Dotted: left alone on purpose. Click any word to inspect it.

Decisions

TypedResultRuleCorpus count

Letter inspector

Click a word in the result or the table.

Settings

How it works

sindhinorm looks at one word at a time. It rewrites only the letters that a non-Sindhi keyboard produces, and only towards a Sindhi letter. Where more than one Sindhi letter could be meant, it picks the spelling that is more frequent in Sindhi Wikipedia.

Typed letterCode pointComes fromBecomes
یU+06CCUrdu or Persian keyboard (Farsi yeh)ي
ىU+0649Arabic keyboard (alef maksura)ي
ےU+06D2Urdu keyboard (yeh barree)ي
ہU+06C1Urdu keyboard (heh goal)ه or ھ
كU+0643Arabic keyboard (Arabic kaf)ڪ or ک
کU+06A9a real Sindhi letter, but also typed for ڪ, which Urdu keyboards lackڪ, only when guarded (see Rules)

Rules

  1. Unicode NFC. Zero-width joiners and non-joiners are removed unless a non-joiner sits between two letters, where it marks a compound or name join.
  2. Keyboard letters (ی ى ے ہ ك) are rewritten towards Sindhi letters and are never written into a word.
  3. Where there is a choice of Sindhi letter, the spelling more frequent in Sindhi Wikipedia wins.
  4. ک becomes ڪ only if the typed form occurs at most 100 times and the other form at least 50 times more often.
  5. A word written entirely in Sindhi letters is otherwise left as it is.
  6. 24 pairs that a native Sindhi speaker judged to be different words (or was unsure about) are never merged, for example کي / ڪي.
  7. Words not in the word list get the usual Sindhi letter for each keyboard letter: ی ى ے → ي, ہ → ه, ك → ڪ.

explain names the rule behind each decision: encoding-merge, lexical-merge, native-keep, lexical-guard, already-canonical, no-variant-letters, unknown-fold or unknown-kept.

Options

from sindhinorm import Normalizer, default_normalizer

lexicon = default_normalizer().lexicon
Normalizer(lexicon, fold_heh=True)        # also merge ه / ھ by frequency (ھن -> هن)
Normalizer(lexicon, mode="frequency")     # the 0.1.0 rules, for reproducing earlier results
Normalizer(lexicon, lex_ratio=50, lex_max_count=100)   # the ک -> ڪ guard

Both heh shapes (ه, ھ) are used in Sindhi, so they are kept as typed unless you set fold_heh=True.

Python API

normalize(text: str) -> str
Normalize text with the bundled word list and default rules.
explain(text: str) -> list[dict]
One entry per word: word, output, rule, count_in, count_out.
default_normalizer() -> Normalizer
The shared normalizer with the bundled word list, loaded once.
Normalizer(lexicon, lex_ratio=50.0, lex_max_count=100, keep=NATIVE_KEEP, mode="keyboard", fold_heh=False)
Methods normalize(text), normalize_word(word), decide(word) → (spelling, rule), explain(text), save(path); class methods Normalizer.default() and Normalizer.load(path) (plain or .gz JSON).
build_lexicon(lines) -> Counter
Word counts from your own corpus, after the same Unicode and zero-width clean-up.

Command line

sindhinorm < input.txt > output.txt
sindhinorm input.txt -o output.txt
sindhinorm explain "ہن آهی کري"
sindhinorm --fold-heh < input.txt > output.txt
sindhinorm --mode frequency < input.txt > output.txt     # 0.1.0 rules
sindhinorm build-lexicon my_corpus.txt -o my_lexicon.json.gz
sindhinorm -l my_lexicon.json.gz < input.txt > output.txt

Evaluation

Measured with the bundled word list on the UD Sindhi test set and on SiPOS, a corpus of clean Sindhi news (Ali et al., 2021).

Test0.2.00.1.0 rules
UD test, every ي typed as ی: altered words restored94.9%94.0%
Same words, one random letter changed (control): "restored"0.3%0.4%
Clean UD words changed0.03%1.35%
Clean SiPOS news words changed0.002%0.39%

The 0.1.0 rules followed Wikipedia's majority spelling even into non-Sindhi letters (عبدالقدير → عبدالقدیر) and between real words (لڪيل → لکيل). Version 0.2.0 makes neither change.

POS tagging

A preregistered test: part-of-speech taggers trained on SiPOS, scored on clean test text and on the same text typed as an Urdu keyboard would (61% of tokens altered). Word-level BiLSTM tagger, mean of three seeds.

Test textNo normalizerWith sindhinorm 0.2.0Change (95% CI)
Typed on an Urdu keyboard0.4940.924+0.430 [+0.382, +0.478]
Clean0.9820.981−0.002 [−0.013, +0.010]
Normalization recovers 88% of the accuracy that keyboard typing costs, with no measurable change on correctly typed text. A character-level tagger gains +0.30 and a replication on UD Sindhi +0.26.

Limits

  • Frequency cannot always tell a rare real word from a typing slip when ک and ڪ both give real words; the native keep-list covers the 24 reviewed cases.
  • The keep-list is applied without context, so تہ and کی stay as typed even where they are clearly typing slips for ته and کي.
  • One native reviewer. Sindhi only; there is no Urdu mode.

Changelog

0.2.0

  • New default keyboard mode: only letters produced by Urdu, Persian or Arabic keyboards are rewritten, towards Sindhi letters; correct Sindhi is left alone. Clean news text changed: 0.39% → 0.002%.
  • fold_heh=True merges the two heh shapes by frequency; mode="frequency" reproduces 0.1.0.
  • Tested downstream: a POS tagger on keyboard-typed text goes from 0.494 to 0.924 accuracy.

0.1.0

  • First release: corpus-guided, native-validated normalizer, normalize, explain and the command line.

Cite

@software{kaleem_sindhinorm,
  author    = {Kaleem, Arsalan},
  title     = {sindhinorm: a corpus-guided, native-validated spelling normalizer for Sindhi},
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.24093293},
  url       = {https://doi.org/10.5281/zenodo.24093293}
}

The DOI above always points to the newest version. To cite an exact version: 0.2.0 is 10.5281/zenodo.24448229 and 0.1.0 is 10.5281/zenodo.24093294.

License

Code: MIT. Bundled word list: CC BY-SA 4.0, derived from Sindhi Wikipedia (2023-11-01) by Wikipedia contributors. Part of the MorphoTok-SD-UR project.