Skip to main content
Semantic checking goes beyond N-gram statistics by using BERT/RoBERTa masked language models to evaluate whether each word fits its surrounding context. This is an opt-in feature, and mySpellChecker does not ship with pre-trained models. You train your own model on a Myanmar corpus using the training pipeline, then point the config at your exported ONNX file. Semantic Checking uses a Masked Language Model (MLM) to detect context errors by masking each word and comparing model predictions against the original. This is the AI-powered strategy at priority 70 in the validation pipeline.

How It Works

Masked Language Modeling

Semantic checking uses BERT/RoBERTa-style masked language modeling:

Confidence Scoring

The model provides confidence scores for:
  • Original word fit: How well the word fits the context
  • Alternative suggestions: Better-fitting words
  • Error probability: Likelihood that original is wrong

Architecture

Model Architecture

Components:
  • Tokenizer: Myanmar-optimized WordPiece/BPE
  • Encoder: BERT/RoBERTa transformer (6-12 layers)
  • MLM Head: Masked language model prediction head

ONNX Runtime

For production, models are exported to ONNX for:
  • Faster inference: Optimized runtime
  • CPU efficiency: INT8 quantization
  • Portability: No PyTorch dependency

Configuration

Enable Semantic Checking

Advanced Configuration

Extended Myanmar Characters

The allow_extended_myanmar flag is set on the SemanticChecker constructor (not SemanticConfig):

Confidence Calibration

The semantic checker automatically calibrates logit scores based on the detected model family: Override with logit_scale if your model needs different calibration:

Graceful Degradation

If semantic checking fails to initialize, the checker continues without it:

Using Semantic Checking

Basic Usage

Direct API Access

Sentence Scanning

Training Your Model

You need to train your own model before using semantic checking. The quickest path:
This trains a tokenizer, model, and exports to ONNX in one step. See the Training Guide for full configuration options, corpus requirements, and GPU setup.

Manual ONNX Export

The train-model command automatically exports to ONNX format. For manual export or re-quantization, use the Python API:

Performance Characteristics

Benchmarks

The following numbers are illustrative, from a specific training run. Your results will vary based on corpus size, model architecture, and hardware.
Actual accuracy depends on your corpus quality, domain coverage, and model size. Train and evaluate on your own data.

Model Size Guide

These are example training configurations you can use with TrainingConfig. Results vary depending on corpus size and domain.

Word-Aligned Masking

Myanmar words are often split into multiple BPE subword tokens. The semantic checker uses word-aligned masking to handle this correctly:
When predicting, the checker uses beam search to combine predictions across multiple masked positions, finding the most likely complete word (not just individual token predictions). This avoids the “diagonal selection” problem where independently selecting the best token at each position produces nonsensical combinations. Word-aligned masking is enabled by default (word_alignment_enabled=True).

Cache Management

The semantic checker maintains internal caches for tokenization and word-token alignment:
Cache sizes:
  • Encoding cache: LRU 512 entries (tokenization results)
  • Alignment cache: LRU 256 entries (word-token alignment mappings)
Both caches are thread-safe.

Common Patterns

Conditional Semantic Checking

Caching Predictions

GPU Batch Processing

Troubleshooting

Issue: Model loading fails

Cause: Missing model files or incompatible version Solution:

Issue: Slow inference

Cause: Unquantized model or insufficient threads Solution:

Issue: Poor accuracy

Cause: Model not trained on similar data or corpus too small Solution: Retrain with a larger or more domain-specific corpus, or use a bigger architecture:

Issue: High memory usage

Cause: Large model architecture Solution: Train a smaller model:

Next Steps