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
- 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
Theallow_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:Manual ONNX Export
Thetrain-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:word_alignment_enabled=True).
Cache Management
The semantic checker maintains internal caches for tokenization and word-token alignment:- Encoding cache: LRU 512 entries (tokenization results)
- Alignment cache: LRU 256 entries (word-token alignment mappings)
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
- Training Guide - Required: train your own model before using semantic checking
- Semantic Algorithm - Deep dive into the MLM approach
- Performance Tuning - Optimize inference speed