Azerbaijani Spelling Corrector (small, char-level Transformer)

Word-level spelling correction for Azerbaijani: transliteration (ə→e, ş→s, ç→c, ğ→g, ı→i, ö→o, ü→u), keyboard, insertion and deletion errors.

  • Architecture: character-level encoder–decoder Transformer, Pre-LN, 6 encoder / 2 decoder layers, d_model=256, 4 heads, tied embeddings — 6.9M parameters
  • Vocabulary: 37 characters, input is NFC-normalized and lowercased (Azerbaijani I/ı, İ/i aware)
  • Max word length seen in training: 21
  • lexicon.txt: 65,051 known correct words; a beam hypothesis from the lexicon replaces the model's output only when the model is unsure (settings in decoding.json, loaded automatically)

Trained on LocalDoc/spell_mistake_correct_pairs_azerbaijani.

Evaluation

Held-out test set: new misspellings of known words (no input string is shared with training). Real-word errors (a misspelling that is itself a valid word) are excluded: they need sentence context. Decoding: beam10+lex gap=0.25 keep_if_model_keeps=True

Metric Value
Word accuracy (all, incl. already-correct words) 0.9739
Word accuracy (misspelled words only) 0.9727
CER 0.0043
False-correction rate (correct word changed) 0.0114
Word accuracy, unseen words (misspelled only) 0.6301
False-correction rate, unseen words 0.1002
Error type Accuracy
DELETION 0.9657
IDENTITY 0.9886
INSERTION 0.9338
KEYBOARD 0.9052
TRANSLITERATION 0.9888

Usage

# pip install torch huggingface_hub safetensors
import sys
from huggingface_hub import snapshot_download

path = snapshot_download("LocalDoc/azerbaijani-spell-corrector-small")
sys.path.insert(0, path)
from modeling_az_spell import SpellCorrector

corrector = SpellCorrector.from_pretrained(path)          # or SpellCorrector.from_pretrained("LocalDoc/azerbaijani-spell-corrector-small")
print(corrector.correct("seher"))                         # recommended settings from decoding.json
print(corrector.correct(["kitabxanada", "gozel", "Bakida"]))
print(corrector.correct("seher", beam_size=1, use_lexicon=False))   # fastest: plain greedy model

The model corrects single words; split text into tokens first. Capitalization of the input is restored in the output (preserve_case=True). Recommended decoding settings are also stored in decoding.json.

Limitations: words outside the training vocabulary are corrected much less reliably (see the unseen words rows above), especially deletion and keyboard errors.

Downloads last month
-
Safetensors
Model size
6.86M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train LocalDoc/azerbaijani-spell-corrector-small