The Problem: Traditional Edit Distance
Traditional spell checking calculates the Levenshtein edit distance between an input word and every word in the dictionary:The Solution: Symmetric Delete
SymSpell’s key insight: Instead of comparing words directly, pre-compute all possible deletions.Why “Symmetric”?
If we delete characters from both the dictionary word AND the misspelled word, they’ll meet in the middle:How It Works
1
Indexing (Build Time)
For each word in the dictionary, generate all possible deletions up to Store in hash map:
max_edit_distance (typically 2):2
Lookup (Query Time)
When checking a misspelled word, generate its deletions too:
3
Match
Look up each deletion in the pre-built index:Result: Found candidate “မြန်မာ” in O(1) hash lookup!
Visual Example: Syllable Correction
Visual Example: Word Correction
Myanmar-Specific Considerations
Character Clusters
Myanmar characters often form clusters (consonant + medials + vowels). SymSpell treats each Unicode code point as a unit:Common Myanmar Typos SymSpell Catches
Syllable vs Word Level
mySpellChecker applies SymSpell at two levels: 1. Syllable Level (faster, catches 90% of errors):Performance Characteristics
Time Complexity
Where:
- V = vocabulary size
- L = average term length
- d = max edit distance
Space Complexity
SymSpell trades memory for speed:Benchmark: Myanmar Dictionary
Source docstring notes: “Typical Myanmar corpus (100K terms, d=2): ~50-100MB index.” Memory grows with
max_edit_distance — values above 2 cause exponential growth.
Configuration
SpellCheckerConfig Options
Edit Distance Guidelines
Prefix Length
Theprefix_length parameter optimizes memory by only indexing the first N characters:
Implementation Details
Index Structure
Lookup Algorithm
Suggestion Dataclass
Each suggestion returned bylookup() includes:
Additional Methods
Comparison with Other Algorithms
SymSpell is the fastest for dictionary-based spell checking, making it ideal for real-time applications.
See Also
- Edit Distance - Levenshtein distance calculation
- Syllable Validation - Syllable-level checking
- Word Validation - Word-level checking
- Performance Tuning - Optimization strategies