Skip to main content
The validation pipeline is composed of independent strategies, each targeting a specific error type, from tone mark disambiguation to AI-powered semantic analysis. Strategies execute in priority order and share context so later strategies can skip positions already flagged by earlier ones.

Overview

The validation pipeline processes text through multiple strategies, each checking for different error types: Lower priority values run first.

Fast-Path Exit

When enable_fast_path is True (the default), the pipeline uses a two-phase execution model:
  1. Structural phase (priority ≤ 25): Tone, Orthography, Syntactic, and BrokenCompound strategies always run.
  2. 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.
This dramatically reduces false positives on clean text — most sentences have no structural errors, and the contextual strategies are the primary source of false positives.

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 shared ValidationContext containing sentence-level information:

Context Attributes

Strategy Implementations

ToneValidationStrategy (Priority: 10)

Handles tone mark disambiguation using context. Accepts an optional provider for word frequency lookup to suppress ambiguous high-frequency forms.
Detection:
  • Missing tone marks (ငါ → ငါး in number context)
  • Wrong tone marks based on context
  • Ambiguous words resolved by surrounding words
Frequency-based suppression: When both the original word and the correction are high-frequency (above 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 optional provider for sorting suggestions by dictionary validity.
Detection:
  • 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.
Detection:
  • 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.
Parameters: 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
Example: “မနက် ဖြန်” (wrongly split) is flagged because “မနက်ဖြန်” (tomorrow) is a valid compound that is much more common than the rare component “ဖြန်”.

POSSequenceValidationStrategy (Priority: 30)

Validates POS tag sequences against expected patterns.
Detection:
  • 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 ဖြစ်ပါသည်
POS disambiguation: When tags contain | (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.
Detection:
  • 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
Enclitic Question Particles: The strategy detects question particles attached directly to verbs (enclitics):
Negative Indefinite Handling: The strategy correctly identifies negative indefinite constructions as statements, not questions:

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.
Parameters: 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)
Detection:
  • 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.
Detection:
  • Low probability word pairs
  • Unusual word combinations
  • Real-word errors (correct spelling, wrong context)

HomophoneValidationStrategy (Priority: 45)

Detects homophone confusion based on context.
Parameters:
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().
Detection:
  • 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 configure SemanticConfig with the model path and set use_proactive_scanning=True.
use_proactive_scanning defaults to False. Without setting it to True, this strategy produces no errors even if a semantic model is loaded. Both a trained model and use_proactive_scanning=True are required.
Parameters: Detection (two independent sub-checks):
  1. Proactive semantic scan: Masks each word and checks if MLM predictions disagree strongly with the original, limited to 8 predict_mask() calls per sentence
  2. Animacy detection: Flags inanimate subjects before subject/topic particles (က, ကို, သည်, မှာ, တွင်) and always runs even when proactive scanning is skipped
Error budget optimization: Proactive scanning is automatically skipped when there are already errors in the context (from earlier strategies), preventing cascade false positives from corrupted MLM context. Animacy detection is unaffected and always runs. Skipped words: Common function words (particles and conjunctions, 22 words total) are excluded from proactive scanning as MLM disagreement on these is noise.

Creating Custom Strategies

Implement the ValidationStrategy abstract base class:

Strategy Composition

In the default pipeline, SpellChecker coordinates validation directly through its validators:
  1. SyllableValidator: validates each syllable (layer 1)
  2. WordValidator: validates words via SymSpell (layer 2)
  3. ContextValidator: orchestrates validation strategies (layer 3)
The ContextValidator receives a list of strategies built by SpellCheckerBuilder and executes them in priority order within each sentence.

Execution Order

  1. Strategies are sorted by priority (ascending)
  2. Each strategy receives the shared ValidationContext
  3. Strategies can check existing_errors to skip already-flagged words
  4. Strategies add their flagged positions to existing_errors
  5. Errors from all strategies are collected and returned

Configuration

Enable/disable strategies via configuration:

Error Types

Each strategy produces specific error types:

Best Practices

  1. Priority Selection: Choose priorities that make sense for your validation order
  2. Skip Flagged Words: Always check existing_errors to avoid duplicate errors
  3. Skip Names: Respect the is_name_mask to avoid flagging proper names
  4. Confidence Scores: Use appropriate confidence levels for your error type
  5. Performance: Heavy validations (semantic) should run last

See Also