Overview
The validation pipeline processes text through multiple strategies, each checking for different error types:
Lower priority values run first.
Fast-Path Exit
Whenenable_fast_path is True (the default), the pipeline uses a two-phase execution model:
- Structural phase (priority ≤ 25): Tone, Orthography, Syntactic, and BrokenCompound strategies always run.
- Contextual phase (priority > 25): POS sequence, Question, Homophone, Confusable, N-gram, and Semantic strategies only run if the structural phase found at least one error.
Configuration
Trade-offs
The fast-path cutoff is at priority 25 (after BrokenCompoundStrategy). Strategies at priority 30+ (POS sequence, homophone, confusable, n-gram, semantic) are skipped on structurally clean sentences. If you need full contextual validation on all input, set
enable_fast_path=False.ValidationContext
All strategies receive a sharedValidationContext containing sentence-level information:
Context Attributes
Strategy Implementations
ToneValidationStrategy (Priority: 10)
Handles tone mark disambiguation using context. Accepts an optionalprovider for word frequency lookup to suppress ambiguous high-frequency forms.
- Missing tone marks (ငါ → ငါး in number context)
- Wrong tone marks based on context
- Ambiguous words resolved by surrounding words
high_freq_threshold), the error is suppressed. This prevents false positives on grammatically ambiguous forms like သူ့ (possessive) vs သူ (subject) where both are valid.
OrthographyValidationStrategy (Priority: 15)
Validates medial consonant ordering and compatibility (UTN #11 rules) at the word level. Uses a two-step check: medial order first, then compatibility. Accepts an optionalprovider for sorting suggestions by dictionary validity.
- Medial order errors: Incorrect medial consonant order (e.g., ွ before ျ), which generates stripped variant suggestions
- Compatibility errors: Incompatible medial-consonant combinations with no suggestions, because the combination is invalid
SyntacticValidationStrategy (Priority: 20)
Validates grammar rules and particle usage.- Particle errors (မှာ vs မှ)
- Medial confusion (ျ vs ြ)
- Missing particles
- Invalid word combinations
- Duplicated sentence endings (e.g., သည်သည်), detected via fast-path before full syntactic check
- Split polite forms (ပါတယ် → ပါ + တယ်), automatically skipped to avoid false positives
BrokenCompoundStrategy (Priority: 25)
Detects compound words that were incorrectly split by a space. This is the inverse of merged word detection — instead of finding words that were wrongly joined, it finds words that were wrongly separated.
Detection:
- Adjacent word pairs whose concatenation forms a valid, common dictionary word
- At least one component must be a rare word (below
rare_threshold) - The compound form must be significantly more common than the rarer component
- Skips Pali/Sanskrit stacking fragments (virama U+1039) to avoid false positives
POSSequenceValidationStrategy (Priority: 30)
Validates POS tag sequences against expected patterns.- P-P: Consecutive particles → error (always flagged)
- N-N: Consecutive nouns without particle → warning (logged, not surfaced as error)
- V-V: Consecutive verbs → info (serial verb constructions are usually valid)
- V+N / N+V multi-POS check: When a noun also has V in its dictionary POS, validates context
- Sentence-final predicate check: Flags sentences with structural particles but no verb, suggests ဖြစ်သည် or ဖြစ်ပါသည်
| (multi-POS), the optional pos_disambiguator resolves them using context-based R1-R5 rules before validation. Disambiguated tags are stored back in context for downstream strategies.
Serial Verb Support:
Myanmar is a serial verb language where verb-verb (V-V) sequences are often valid. The strategy recognizes valid serial verb constructions:
- Auxiliary verbs: နေ (progressive), ထား (resultative), လိုက် (action manner)
- Modal verbs: နိုင် (ability), ချင် (desire), ရ (permission)
- Directional verbs: သွား (away), လာ (toward)
QuestionStructureValidationStrategy (Priority: 40)
Validates question sentence structure.- Missing question particles (လား, သလဲ)
- Wrong question particle for context
- Question word agreement
- Implicit questions: 2nd-person pronouns + completive endings detected as implicit questions (lower confidence ~0.55)
- Malformed question endings: Split ရဲ့ လဲ tokens merged and corrected
- Segmentation fragment filtering: Question words adjacent to previous word (no space gap) are masked to prevent false positives
ConfusableSemanticStrategy (Priority: 48), Opt-in Required
MLM-enhanced confusable detection that uses masked language modeling to catch valid-word confusables. Dynamically generates confusable variants using phonetic rules (aspiration swaps, medial swaps, tone mark changes, nasal endings) and uses MLM logits to determine if a variant is more likely in context. Requires a trained ONNX model.
Asymmetric thresholds protect against false positives with stacking penalties:
- Base threshold (highest wins): high-frequency word (6.0), current in top-K (5.0), medial ျ↔ြ swap (2.0), default (3.0)
- Additive penalties: frequency-ratio (+2.0 or +1.0), visarga-pair (+2.0), sentence-final (+0.5)
- Generates confusable variants dynamically from phonetic rules (aspiration swaps, medial swaps, tone marks, nasal endings)
- Uses a single
predict_mask()call per candidate word to compare MLM logits - Skips positions already flagged by earlier strategies
- High-frequency visarga pairs (both words above threshold) are hard-blocked to prevent false positives
NgramContextValidationStrategy (Priority: 50)
Uses bigram/trigram probabilities to detect unlikely sequences.- Low probability word pairs
- Unusual word combinations
- Real-word errors (correct spelling, wrong context)
HomophoneValidationStrategy (Priority: 45)
Detects homophone confusion based on context.Legacy kwargs (
improvement_ratio, min_probability, high_freq_threshold, high_freq_improvement_ratio) are accepted but ignored for backward compatibility. These thresholds are managed internally by NgramContextChecker.compute_required_ratio().- Homophone pairs (ကား/ကာ, သာ/သား)
- Context-based correct form selection
- Sound-alike word confusion
SemanticValidationStrategy (Priority: 70), Opt-in Required
AI-powered validation using ONNX models. This strategy is not active by default. You must train a semantic model first, then configureSemanticConfig with the model path and set use_proactive_scanning=True.
Detection (two independent sub-checks):
- Proactive semantic scan: Masks each word and checks if MLM predictions disagree strongly with the original, limited to 8
predict_mask()calls per sentence - Animacy detection: Flags inanimate subjects before subject/topic particles (က, ကို, သည်, မှာ, တွင်) and always runs even when proactive scanning is skipped
Creating Custom Strategies
Implement theValidationStrategy abstract base class:
Strategy Composition
In the default pipeline,SpellChecker coordinates validation directly through its validators:
- SyllableValidator: validates each syllable (layer 1)
- WordValidator: validates words via SymSpell (layer 2)
- ContextValidator: orchestrates validation strategies (layer 3)
ContextValidator receives a list of strategies built by SpellCheckerBuilder and executes them in priority order within each sentence.
Execution Order
- Strategies are sorted by priority (ascending)
- Each strategy receives the shared
ValidationContext - Strategies can check
existing_errorsto skip already-flagged words - Strategies add their flagged positions to
existing_errors - Errors from all strategies are collected and returned
Configuration
Enable/disable strategies via configuration:Error Types
Each strategy produces specific error types:Best Practices
- Priority Selection: Choose priorities that make sense for your validation order
- Skip Flagged Words: Always check
existing_errorsto avoid duplicate errors - Skip Names: Respect the
is_name_maskto avoid flagging proper names - Confidence Scores: Use appropriate confidence levels for your error type
- Performance: Heavy validations (semantic) should run last
See Also
- Grammar Checkers - Rule-based grammar validation
- Context Checking - N-gram context validation
- POS Tagging - Part-of-speech tagging
- Semantic Checking - MLM-based deep context analysis
- Training Custom Models - Train your own AI models