Model Training Overview
The Semantic Router relies on multiple specialized classification models to make intelligent routing decisions. This section provides a comprehensive overview of the training process, datasets used, and the purpose of each model in the routing pipeline.
Training Architecture Overview
The Semantic Router employs a multi-task learning approach using ModernBERT as the foundation model for various classification tasks. Each model is trained for specific purposes in the routing pipeline:
Why ModernBERT?
Technical Advantages
ModernBERT represents the latest evolution in BERT architecture with several key improvements over traditional BERT models:
1. Enhanced Architecture
- Rotary Position Embedding (RoPE): Better handling of positional information
- GeGLU Activation: Improved gradient flow and representation capacity
- Attention Bias Removal: Cleaner attention mechanisms
- Modern Layer Normalization: Better training stability
2. Training Improvements
- Longer Context: Trained on sequences up to 8,192 tokens vs BERT's 512
- Better Data: Trained on higher-quality, more recent datasets
- Improved Tokenization: More efficient vocabulary and tokenization
- Anti-overfitting Techniques: Built-in regularization improvements
3. Performance Benefits
# Performance comparison on classification tasks
model_performance = {
"bert-base": {
"accuracy": 89.2,
"inference_speed": "100ms",
"memory_usage": "400MB"
},
"modernbert-base": {
"accuracy": 92.7, # +3.5% improvement
"inference_speed": "85ms", # 15% faster
"memory_usage": "380MB" # 5% less memory
}
}
Why Not GPT-based Models?
| Aspect | ModernBERT | GPT-3.5/4 |
|---|---|---|
| Latency | ~20ms | ~200-500ms |
| Cost | $0.0001/query | $0.002-0.03/query |
| Specialization | Fine-tuned for classification | General purpose |
| Consistency | Deterministic outputs | Variable outputs |
| Deployment | Self-hosted | API dependency |
| Context Understanding | Bidirectional | Left-to-right |
Training Methodology
Unified Fine-tuning Framework
Our training approach uses a unified fine-tuning framework that applies consistent methodologies across all classification tasks:
Anti-Overfitting Strategy
# Adaptive training configuration based on dataset size
def get_training_config(dataset_size):
if dataset_size < 1000:
return TrainingConfig(
epochs=2,
batch_size=4,
learning_rate=1e-5,
weight_decay=0.15,
warmup_ratio=0.1,
eval_strategy="epoch",
early_stopping_patience=1
)
elif dataset_size < 5000:
return TrainingConfig(
epochs=3,
batch_size=8,
learning_rate=2e-5,
weight_decay=0.1,
warmup_ratio=0.06,
eval_strategy="steps",
eval_steps=100,
early_stopping_patience=2
)
else:
return TrainingConfig(
epochs=4,
batch_size=16,
learning_rate=3e-5,
weight_decay=0.05,
warmup_ratio=0.03,
eval_strategy="steps",
eval_steps=200,
early_stopping_patience=3
)