Typo Correction Example
Basic correction
Section titled “Basic correction”from sinlib import TypoDetector
detector = TypoDetector.from_pretrained("Ransaka/sinlib")
result = detector("අපකරියට ගිය")print(result)# 'අපකීර්තියට ගිය'Suggestions
Section titled “Suggestions”suggestions = detector.suggest_correction("අඩිරාජ")print(suggestions)# ['අධිරාජ']Checking valid words
Section titled “Checking valid words”# A correctly spelled word passes through unchangedresult = detector("මගේ ගෙදර ලස්සනයි")print(result)# 'මගේ ගෙදර ලස්සනයි'Scoring words manually
Section titled “Scoring words manually”prob = detector.word_ngram_probability("සිංහල")print(prob)# ~3.2e-05 — plausible word
prob = detector.word_ngram_probability("xzqabc")print(prob)# ~1e-27 — implausible, would be correctedTuning threshold
Section titled “Tuning threshold”# Stricter: flag more wordsstrict = TypoDetector(threshold=1e-6)
# Lenient: only obvious typoslenient = TypoDetector(threshold=1e-12)