Skip to main content
Pre-trained Myanmar language models are scarce and rarely cover domain-specific vocabulary. Instead of shipping generic models that underperform, mySpellChecker provides training pipelines so you can build models tuned to your exact corpus, handling tokenizer creation, model training, and ONNX export end-to-end.

Overview

mySpellChecker provides two training pipelines:

1. Semantic Model (MLM) Training

Trains a custom Masked Language Model for semantic validation:

2. Neural Reranker Training

Trains a small MLP to re-rank spell checker suggestions using learned feature weights:

Prerequisites

Install the training dependencies:
This installs:
  • torch - PyTorch for model training
  • transformers - HuggingFace Transformers for model architectures
  • tokenizers - Fast tokenizer library
  • onnx - ONNX export support
  • onnxruntime - ONNX inference runtime

Quick Start

The simplest way to train a model:

Model Architectures

The training pipeline supports two transformer architectures:

RoBERTa (Default)

RoBERTa (Robustly Optimized BERT Pretraining Approach) is recommended for most use cases:
Key characteristics:
  • Dynamic masking during training
  • No Next Sentence Prediction (NSP) objective
  • Larger batch sizes and more training data typically improve results

BERT

BERT (Bidirectional Encoder Representations from Transformers):
Key characteristics:
  • Static masking
  • Includes NSP objective capability
  • Well-suited for tasks requiring sentence-pair understanding

Configuration Options

TrainingConfig Parameters

Architecture Constraints

The hidden_size must be divisible by num_heads. Valid combinations include:
  • hidden_size=256, num_heads=4 (64 per head)
  • hidden_size=256, num_heads=8 (32 per head)
  • hidden_size=512, num_heads=8 (64 per head)

Learning Rate Scheduling

The training pipeline uses linear learning rate scheduling with warmup:
The learning rate:
  1. Starts at 0
  2. Linearly increases to learning_rate over warmup_ratio * total_steps
  3. Linearly decreases to 0 over remaining steps

Resume Training from Checkpoint

Training can be resumed from a checkpoint if interrupted:
Checkpoints are saved every 500 steps by default.

Training Metrics

When save_metrics=True (default), training metrics are saved to training_metrics.json:
Metrics include:
  • step: Global training step
  • epoch: Current epoch (fractional)
  • loss: Training loss
  • learning_rate: Current learning rate

Low-Level API

For more control, use ModelTrainer directly:

ONNX Export

Models are automatically exported to ONNX format with INT8 quantization:
The exported ONNX model can be used with SemanticChecker for context-aware validation. Output Files:
  • model.onnx - Quantized model (default)
  • model.base.onnx - Original FP32 model
  • tokenizer.json - Copied for convenience

Using Trained Models

With SemanticChecker

Standalone Inference

CLI Usage

Train a model via CLI:

Corpus Format

The training corpus should be a text file with one sentence per line:
Requirements:
  • UTF-8 encoding
  • One sentence per line
  • Minimum 100 lines (recommended: 10,000+ lines)
  • Segmented text (spaces between words) works best

GPU Support

Training automatically uses GPU if available:

Batch Size by GPU VRAM

For CPU-only training:

Model Size vs Quality

Best Practices

  1. Corpus Size: Use at least 10,000 sentences for meaningful results
  2. Batch Size: Larger batches (16-32) generally train faster on GPU
  3. Hidden Size: Start with 256 for small models, 512 for larger ones
  4. Epochs: 5-10 epochs is usually sufficient; monitor loss for overfitting
  5. Warmup: 10% warmup (0.1) helps training stability
  6. Checkpoints: Enable keep_checkpoints=True for long training runs
  7. Metrics: Always save metrics to monitor training progress

Troubleshooting

Memory Issues

Slow Training

Invalid hidden_size/num_heads

Neural Reranker Training

The neural reranker is a small MLP (Linear(19→64)→ReLU→Dropout→Linear(64→1), ~5K parameters) that learns to re-rank spell checker suggestions using 19 extracted features. It runs as the final step in the suggestion pipeline after N-gram and semantic reranking. See Neural Reranker for the full feature vector layout.

Prerequisites

Requires:
  • A production SQLite database (built by the data pipeline)
  • A segmented Arrow IPC corpus (produced during pipeline ingestion)
  • PyTorch: pip install myspellchecker[train]

Step 1: Generate Training Data

The RerankerDataGenerator creates labeled training data by corrupting clean sentences and collecting spell checker candidates:
For large-scale generation, use the threaded entry point:
Each JSONL line contains 19 features per candidate (edit distance, frequency, phonetic similarity, N-gram context, confusable status, source indicators, etc.) plus the gold correction index. See Neural Reranker for the full feature layout.

Step 2: Train the MLP

Training parameters: CLI alternative:

Step 3: Use the Trained Model

See Neural Reranker for inference details and the feature vector specification.

See Also