File size: 5,625 Bytes
fb3b54d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# 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)