BERT Fine-tuning › Practical Recommendations
Language AI HandbookAll chapters BERT Fine-tuning › Practical RecommendationsOne section · Sections in this chapter8 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Successful fine-tuning requires balancing several factors. Here are concrete recommendations based on the original BERT paper and subsequent research.
Standard Recipe
For most classification and sequence labeling tasks:
| Parameter | Recommended Value |
|---|---|
| Learning rate | 2e-5 to 5e-5 |
| Batch size | 16 or 32 |
| Epochs | 2-4 |
| Warmup ratio | 10% of total steps |
| Weight decay | 0.01 |
| Max sequence length | 128-512 (task-dependent) |
| Dropout | 0.1 |
Dataset Size Guidelines
The amount of training data affects hyperparameter choices:
- Small datasets (< 1K examples): Use lower learning rates (1e-5), more epochs (4-5), and consider layer freezing
- Medium datasets (1K-10K examples): Standard settings work well
- Large datasets (> 10K examples): Can use larger learning rates (5e-5), fewer epochs (2-3)
Task-Specific Considerations
Different tasks benefit from different approaches:
Classification: Standard recipe works well. Focus on class imbalance if present.
Sequence labeling (NER, POS): Handle subword alignment carefully. Consider CRF layer on top for structured prediction.
Question answering: Use longer max sequence lengths (384-512). Handle impossible questions by allowing null predictions.
Sentence pair tasks: Use segment embeddings. Consider whether task requires symmetric (similarity) or asymmetric (entailment) modeling.
When Fine-tuning Fails
If results are poor, try these debugging steps:
- Check data quality: Are labels correct? Is the task well-defined?
- Try different learning rates: Run a sweep from 1e-5 to 5e-5
- Increase training data: Can you augment or synthesize examples?
- Use a different model size: BERT-Large may help for complex tasks
- Consider domain mismatch: Pre-train further on domain-specific data first