SpellChecker behavior is controlled by the SpellCheckerConfig object. You can adjust performance thresholds, toggle features, and fine-tune algorithm sensitivity through nested configuration classes.
Usage
The easiest way to configure the spell checker is usingConfigPresets with the SpellCheckerBuilder.
Configuration Presets
Configuration Profiles
For environment-specific configurations, useget_profile() which returns fully-configured SpellCheckerConfig objects tuned for specific use cases.
ConfigPresets (from SpellCheckerBuilder) and get_profile() are separate configuration systems. Presets are simpler toggles; profiles provide fully-tuned configurations including SymSpell, N-gram, POS tagger, and provider settings.Configuration Files
You can load configuration from a YAML file instead of code. This is useful for deploying the spell checker in different environments. Load Order:- Explicit path loaded via
ConfigLoader().load(config_file="path/to/config.yml"). myspellchecker.yaml,myspellchecker.yml, ormyspellchecker.jsonin the current directory.~/.config/myspellchecker/myspellchecker.yaml,myspellchecker.yml, ormyspellchecker.json(User global config).
myspellchecker.yaml:
Configuration Parameters
General Settings
int
default:"2"
Maximum edit distance for suggestions (1-3). Higher values find more suggestions but are slower.
int
default:"5"
Maximum number of correction suggestions to return per error.
int
default:"100000"
Maximum input text length in characters. Prevents resource exhaustion on very large inputs.
bool
default:"True"
Enable phonetic matching (Myanmar Soundex-like) for finding sound-alike corrections.
bool
default:"True"
Enable N-gram context validation for detecting real-word errors.
bool
default:"True"
Enable Named Entity Recognition heuristics to skip proper names.
bool
default:"True"
Enable algorithmic syllable structure checks.
str
default:"myword"
Word segmentation engine:
"myword", "crf", or "transformer".str | None
default:"None"
Custom model name or path for transformer word segmentation. Only used when
word_engine="transformer". Defaults to chuuhtetnaing/myanmar-text-segmentation-model.int
default:"-1"
Device for transformer word segmentation inference.
-1 for CPU, 0+ for GPU index. Only used when word_engine="transformer".bool
default:"False"
Silently use empty provider if database not found (instead of raising error).
Nested Configuration Objects
SymSpellConfig
SymSpell algorithm configuration (edit distance, prefix length, beam width).
NgramContextConfig
N-gram context checker configuration (thresholds, smoothing, scoring weights).
PhoneticConfig
Phonetic matching configuration (code length, suggestion thresholds).
SemanticConfig
Semantic model configuration (model path, tokenizer, inference settings).
POSTaggerConfig
POS tagger configuration (tagger type, model name, device).
JointConfig
Joint segmentation-tagging configuration (beam width, emission weight).
ValidationConfig
Validation behavior configuration (confidence thresholds, feature toggles).
ProviderConfig
Provider caching and query configuration (cache size, timeout).
AlgorithmCacheConfig
Unified cache size configuration for all algorithm lookup caches.
RankerConfig
Suggestion ranking weights and strategy selection.
FrequencyGuardConfig
Centralized frequency thresholds that suppress false positives across validators (colloquial, homophone, N-gram, semantic).
CompoundResolverConfig
Compound word synthesis and broken compound detection settings.
ReduplicationConfig
Reduplication validation settings for AABB/ABAB patterns.
NeuralRerankerConfig
Neural suggestion re-ranking model configuration (MLP with ONNX).
BrokenCompoundStrategyConfig
Broken compound detection strategy thresholds and confidence.
TokenRefinementConfig
Token boundary refinement scoring (exposes hidden errors in merged tokens).
NERConfig
default:"None"
NER model configuration. When provided with
enabled=True, uses specified NER model.SymSpell Settings
Controlled via thesymspell attribute (SymSpellConfig).
Context & N-gram Settings
Controlled via thengram_context attribute (NgramContextConfig).
Phonetic Settings
Controlled via thephonetic attribute (PhoneticConfig).
Semantic Model Settings
Controlled via thesemantic attribute (SemanticConfig). Requires a trained model.
Proactive Semantic Scanning
When enabled, the spell checker will proactively scan sentences for semantic errors using a language model (XLM-RoBERTa, mDeBERTa, etc.). This can detect errors that traditional dictionary-based methods miss.POS Tagger Settings
Controlled via thepos_tagger attribute (POSTaggerConfig).
Validation & Error Detection Settings
Controlled via thevalidation attribute (ValidationConfig).
Provider Settings
Controlled via theprovider_config attribute (ProviderConfig).
Connection Pooling
Connection pooling manages SQLite database connections for better resource control and production safety. The library uses connection pooling by default to ensure robust production behavior. Benefits:- Resource control with hard connection limits
- Connection health monitoring and automatic recreation
- Observability through pool statistics
- Graceful degradation under load
- Keep
pool_max_sizesmall (2-5) to reduce lock contention - Set
pool_min_size=1for most cases - Larger pools (>10) degrade performance due to lock contention
- Pooling adds ~30-50% overhead compared to direct connections
- Overhead comes from queue operations, locking, and health checks
- Trade-off: Performance vs. resource control and production safety
- See
tests/test_connection_pool.pyfor comprehensive test coverage
Joint Segmentation-Tagging Settings
Thejoint parameter accepts a JointConfig object for unified word segmentation and POS tagging.
See Segmentation - Joint Mode for detailed usage.
Frequency Guard Settings
Controlled via thefrequency_guards attribute (FrequencyGuardConfig). Centralized thresholds that suppress false positives across validators.
Compound Resolver Settings
Controlled via thecompound_resolver attribute (CompoundResolverConfig). Handles compound word synthesis for OOV recovery.
Reduplication Settings
Controlled via thereduplication attribute (ReduplicationConfig). Validates Myanmar reduplication patterns (AABB, ABAB, rhyme).
Neural Reranker Settings
Controlled via theneural_reranker attribute (NeuralRerankerConfig). MLP-based suggestion re-ranking using ONNX.
Broken Compound Strategy Settings
Controlled via thebroken_compound_strategy attribute (BrokenCompoundStrategyConfig). Tunes the validation strategy that detects incorrectly split compound words.
Token Refinement Settings
Controlled via thetoken_refinement attribute (TokenRefinementConfig). Tunes the validation-time token-lattice refinement pass that exposes hidden error spans in merged tokens (e.g., particle attachment, negation attachment).
Integrated Features
The following features are automatically integrated into the validation pipeline. Most are enabled by default and work transparently.Particle Typo Detection
Automatically detects common Myanmar particle typos usingPARTICLE_TYPO_PATTERNS. Examples:
တယ→တယ်(statement ending, missing asat)နဲ→နဲ့(with, missing tone)သလာ→သလား(question, missing tone)
Medial Confusion Detection
Catches context-aware ျ vs ြ medial confusion usingMEDIAL_CONFUSION_PATTERNS. For example:
ကြီးvsကျီး(big vs crow)ပြုvsပျု(do vs -)
Morphology OOV Recovery
For out-of-vocabulary (OOV) words, the system attempts to recover the root by stripping common suffixes:- Verb suffixes:
သည်,ခဲ့,မည်,နေ, etc. - Noun suffixes:
များ,တို့, etc.
POS Sequence Validation
Uses ViterbiTagger output to detect invalid POS sequences:- V-V (consecutive verbs without particles)
- P-P (consecutive particles)
- Invalid tag sequences defined in
INVALID_POS_SEQUENCES
Question Detection
Identifies sentence types (question/statement) and validates question particle usage:- Detects question words:
ဘာ,ဘယ်,ဘယ်လို, etc. - Validates question particles:
လား,လဲ,သလဲ, etc.
Unified Suggestion Ranking
Suggestions from different sources are ranked usingUnifiedRanker with source-specific weights:
Tone Disambiguation
TheToneDisambiguator provides context-aware correction for commonly confused Myanmar tone marks. Available via:
သား(son, disambiguated by family context patterns)ငါ(I/me vsငါးfish, detects missing visarga in numeral contexts)ပဲ(only vs bean)