| # EthioBBPE Tokenizer - Setup Complete ✅ |
|
|
| ## 📦 What's Ready |
|
|
| ### Datasets Prepared |
| - ✅ **Synaxarium Dataset** (`data/synaxarium_dataset.parquet`) - 366 texts |
| - ✅ **Canon Biblical Dataset** (`data/canon_biblical_am_en.parquet`) - 61,403 texts (Amharic + English) |
| - ✅ **Combined Corpus** (`data/combined_corpus.txt`) - 15.43 MB, 61,769 lines |
|
|
| ### Trained Model |
| - ✅ **Model Name**: `EthioBBPE_AmharicBible` |
| - ✅ **Location**: `models/EthioBBPE_AmharicBible/` |
| - ✅ **Vocabulary Size**: 8,000 tokens |
| - ✅ **Training Duration**: ~29 seconds |
|
|
| ### Generated Files |
| ``` |
| models/EthioBBPE_AmharicBible/ |
| ├── tokenizer.json # 621 KB - Standard tokenizer (required) |
| ├── vocab.json.gz # 61 KB - Compressed vocabulary (64% compression) |
| ├── tokenizer_quantized_8bit.json.gz # 56 KB - Quantized for deployment |
| ├── config.json # 1 KB - Training configuration |
| ├── training_metrics.json # 1 KB - Training statistics |
| ├── special_tokens_map.json # 1 KB - Special tokens mapping |
| └── README.md # 2 KB - Model card |
| ``` |
|
|
| ## 🚀 How to Use |
|
|
| ### Quick Start (Already Done!) |
| ```bash |
| # The tokenizer has been trained and is ready to use |
| ./run_training.sh # Re-run if needed |
| ``` |
|
|
| ### Load in Python |
| ```python |
| from tokenizers import Tokenizer |
| |
| # Load the trained tokenizer |
| tokenizer = Tokenizer.from_file('models/EthioBBPE_AmharicBible/tokenizer.json') |
| |
| # Encode text |
| text = "በመዠመሪያ፡እግዚአብሔር፡ሰማይንና፡ምድርን፡ፈጠረ።" |
| encoded = tokenizer.encode(text) |
| print(f"Tokens: {encoded.tokens}") |
| print(f"IDs: {encoded.ids}") |
| |
| # Decode back |
| decoded = tokenizer.decode(encoded.ids) |
| print(f"Decoded: {decoded}") |
| ``` |
|
|
| ### Load with Transformers |
| ```python |
| from transformers import AutoTokenizer |
| |
| tokenizer = AutoTokenizer.from_pretrained("models/EthioBBPE_AmharicBible") |
| # or upload to Hugging Face Hub and load from there |
| ``` |
|
|
| ### Load Compressed Vocab Directly |
| ```python |
| import gzip |
| import json |
| |
| with gzip.open('models/EthioBBPE_AmharicBible/vocab.json.gz', 'rt', encoding='utf-8') as f: |
| vocab = json.load(f) |
| print(f"Vocab size: {len(vocab)}") |
| ``` |
|
|
| ## 🎯 Advanced Features Enabled |
|
|
| ### 1. Checkpointing |
| - Automatic checkpoint saving during training |
| - SHA256 checksum for integrity verification |
| - Configurable max checkpoints (currently: 3) |
| - Resume capability from last checkpoint |
|
|
| ### 2. Multi-format Compression |
| - **Format**: gzip (level 9) |
| - **Compression Ratio**: ~64% space savings |
| - Also supports: bz2, lzma/xz |
|
|
| ### 3. Model Quantization |
| - **8-bit quantization** enabled for efficient deployment |
| - Creates lookup tables for faster inference |
| - Saved as separate file: `tokenizer_quantized_8bit.json.gz` |
|
|
| ### 4. Training Metrics |
| Comprehensive tracking saved in `training_metrics.json`: |
| - Initial metrics (files processed, total bytes) |
| - Final metrics (vocab size, training duration) |
| - Full configuration snapshot |
|
|
| ### 5. Multiple Export Formats |
| - Standard `tokenizer.json` (Hugging Face compatible) |
| - Compressed `vocab.json.gz` (storage efficient) |
| - Quantized version (deployment optimized) |
| - Hugging Face export files (merges.txt, special_tokens_map.json) |
|
|
| ## 📊 Performance Summary |
|
|
| | Metric | Value | |
| |--------|-------| |
| | Vocabulary Size | 8,000 | |
| | Training Data | 15.43 MB (61,769 texts) | |
| | Training Time | 29.33 seconds | |
| | Compression Ratio | 64.1% | |
| | Languages | Amharic, English, Multilingual | |
| | Special Tokens | `<pad>`, `<unk>`, `<s>`, `</s>`, `<mask>` | |
|
|
| ## 🔧 Re-training Options |
|
|
| ### Change Vocabulary Size |
| ```bash |
| python scripts/train_tokenizer.py \ |
| --data_dir ./data \ |
| --vocab_size 16000 \ |
| --model_name EthioBBPE_Large |
| ``` |
|
|
| ### Different Compression |
| ```bash |
| # Use bz2 compression |
| python scripts/train_tokenizer.py \ |
| --data_dir ./data \ |
| --compression_format bz2 \ |
| --compression_level 9 |
| ``` |
|
|
| ### Disable Features |
| ```bash |
| # Train without quantization |
| python scripts/train_tokenizer.py \ |
| --data_dir ./data \ |
| --no_compression \ |
| --no_checkpoint |
| ``` |
|
|
| ### Custom Special Tokens |
| ```bash |
| python scripts/train_tokenizer.py \ |
| --data_dir ./data \ |
| --special_tokens "<pad>" "<unk>" "<bos>" "<eos>" "<mask>" "<cls>" "<sep>" |
| ``` |
|
|
| ## 📁 Project Structure |
| ``` |
| /workspace/ |
| ├── data/ # Training datasets |
| │ ├── synaxarium_dataset.parquet |
| │ ├── canon_biblical_am_en.parquet |
| │ └── combined_corpus.txt # Prepared training data |
| ├── models/ # Trained models |
| │ ├── EthioBBPE_AmharicBible/ # Current model |
| │ └── checkpoints/ # Training checkpoints |
| ├── scripts/ |
| │ ├── bbpe_trainer.py # Core trainer logic |
| │ ├── train_tokenizer.py # CLI interface |
| │ └── prepare_datasets.py # Dataset preparation |
| ├── run_training.sh # One-command training |
| └── README.md # Documentation |
| ``` |
|
|
| ## 🎓 Next Steps |
|
|
| 1. **Test the Tokenizer**: Try encoding/decoding your own Amharic texts |
| 2. **Upload to Hugging Face Hub**: Share your model with the community |
| 3. **Integrate with Models**: Use with transformer models for Amharic NLP tasks |
| 4. **Fine-tune Parameters**: Adjust vocab size or min_frequency for your use case |
| |
| ## 📞 Support |
| |
| For issues or questions: |
| - Check `models/EthioBBPE_AmharicBible/README.md` for model-specific info |
| - Review `training_metrics.json` for training details |
| - See main `README.md` for comprehensive documentation |
|
|
| --- |
| **Status**: ✅ Ready for Production Use |
| **Last Updated**: $(date) |
|
|