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.
normalize, explain and the Normalizer class.
Command lineNormalize files, explain decisions, build your own word list.
ResultsRestoration rates and a preregistered POS-tagging test.
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 sindhinormPure 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
| Typed | Result | Rule | Corpus 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 letter | Code point | Comes from | Becomes |
|---|---|---|---|
| ی | U+06CC | Urdu or Persian keyboard (Farsi yeh) | ي |
| ى | U+0649 | Arabic keyboard (alef maksura) | ي |
| ے | U+06D2 | Urdu keyboard (yeh barree) | ي |
| ہ | U+06C1 | Urdu keyboard (heh goal) | ه or ھ |
| ك | U+0643 | Arabic keyboard (Arabic kaf) | ڪ or ک |
| ک | U+06A9 | a real Sindhi letter, but also typed for ڪ, which Urdu keyboards lack | ڪ, only when guarded (see Rules) |
Rules
- 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.
- Keyboard letters (ی ى ے ہ ك) are rewritten towards Sindhi letters and are never written into a word.
- Where there is a choice of Sindhi letter, the spelling more frequent in Sindhi Wikipedia wins.
- ک becomes ڪ only if the typed form occurs at most 100 times and the other form at least 50 times more often.
- A word written entirely in Sindhi letters is otherwise left as it is.
- 24 pairs that a native Sindhi speaker judged to be different words (or was unsure about) are never merged, for example کي / ڪي.
- 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 ک -> ڪ guardBoth 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 methodsNormalizer.default()andNormalizer.load(path)(plain or.gzJSON). - 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.txtEvaluation
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).
| Test | 0.2.0 | 0.1.0 rules |
|---|---|---|
| UD test, every ي typed as ی: altered words restored | 94.9% | 94.0% |
| Same words, one random letter changed (control): "restored" | 0.3% | 0.4% |
| Clean UD words changed | 0.03% | 1.35% |
| Clean SiPOS news words changed | 0.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 text | No normalizer | With sindhinorm 0.2.0 | Change (95% CI) |
|---|---|---|---|
| Typed on an Urdu keyboard | 0.494 | 0.924 | +0.430 [+0.382, +0.478] |
| Clean | 0.982 | 0.981 | −0.002 [−0.013, +0.010] |
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=Truemerges 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,explainand 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.