File size: 9,997 Bytes
40bcd86 | 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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | # TraductAL with Romansh Support π¨π
Complete guide for German/English/French to Romansh (Sursilvan) translation using your TraductAL engine with Apertus-8B integration.
---
## π Table of Contents
1. [Quick Start](#quick-start)
2. [System Overview](#system-overview)
3. [Usage Examples](#usage-examples)
4. [Available Models](#available-models)
5. [Romansh Variants](#romansh-variants)
6. [Dataset Information](#dataset-information)
7. [THIRD-PARTY-NOTICES.md](../THIRD-PARTY-NOTICES.md)
8. [Troubleshooting](#troubleshooting)
---
## π Quick Start
### Translate German to Romansh Sursilvan
```bash
cd TraductAL-v1.1.0
python3 unified_translator.py de rm-sursilv "Guten Tag, wie geht es Ihnen?"
```
**Output:**
```
π€ Original (de (German)): Guten Tag, wie geht es Ihnen?
π Translation (rm-sursilv (Romansh Sursilvan)): Bun di, co va cun vos?
π€ Engine: Apertus-8B
β±οΈ Time: 12.30s
```
### List All Supported Languages
```bash
python3 unified_translator.py --list-languages
```
### List Available Models
```bash
python3 unified_translator.py --list-models
```
---
## π― System Overview
TraductAL is powered by a single translation engine:
### **Apertus-8B** (Swiss AI)
- **Languages**: 1,811 (including all Romansh variants)
- **Type**: Causal LLM (decoder-only)
- **Speed**: β‘ 2-5s per sentence on GPU, 10-25s on CPU
- **Best for**: Romansh and low-resource languages, and mainstream pairs alike
- **Quality**: Very high for Swiss languages
- **License**: Apache-2.0 β commercial use permitted
### π€ Engine Selection
Apertus-8B handles every language pair. It is a Romansh specialist, so
Swiss-language pairs are its strongest cases:
| Scenario | Engine Used | Reason |
|----------|-------------|---------|
| German β Romansh | Apertus-8B | Romansh specialist |
| English β German | Apertus-8B | Single engine |
| French β Romansh | Apertus-8B | Romansh specialist |
| Romansh β German | Apertus-8B | Romansh specialist |
---
## π‘ Usage Examples
### Example 1: Basic Translation
```bash
python3 unified_translator.py de rm-sursilv "Willkommen in der Schweiz"
```
### Example 2: French to Romansh
```bash
python3 unified_translator.py fr rm-sursilv "Bonjour, comment allez-vous?"
```
### Example 3: Force Specific Engine
```bash
# Apertus-8B is the only engine
python3 unified_translator.py en de "Hello"
```
### Example 4: Clean Output (No Formatting)
```bash
python3 unified_translator.py de rm-sursilv "Guten Tag" --clean
# Output: Bun di
```
### Example 5: Using Python API Directly
```python
from unified_translator import UnifiedTranslator
translator = UnifiedTranslator()
# Translate with auto engine selection
result = translator.translate(
"Guten Tag",
src_lang="de",
tgt_lang="rm-sursilv"
)
print(result["translation"]) # Output: Bun di
```
### Example 6: Compare Engines (Benchmark)
```bash
python3 unified_translator.py --benchmark
```
---
## π€ Available Models
### Apertus-8B Model
Downloaded on first run; cached at `~/.cache/huggingface/hub/models--swiss-ai--Apertus-8B-2509`
| Model | Size | Languages | Speed | Quality |
|-------|------|-----------|-------|---------|
| Apertus-8B | ~16GB | 1,811 | Slower | Very High |
---
## π¨π Romansh Variants Supported
The system supports **all 6 Romansh variants**:
| Code | Variant | Speakers | Status |
|------|---------|----------|--------|
| `rm-sursilv` | Sursilvan | 55% | β
Primary |
| `rm-vallader` | Vallader | 20% | β
Supported |
| `rm-puter` | Puter | 12% | β
Supported |
| `rm-surmiran` | Surmiran | 10% | β
Supported |
| `rm-sutsilv` | Sutsilvan | 3% | β
Supported |
| `rm-rumgr` | Rumantsch Grischun | Standard | β
Supported |
### Usage with Different Variants
```bash
# Sursilvan (most common)
python3 unified_translator.py de rm-sursilv "Guten Tag"
# Vallader
python3 unified_translator.py de rm-vallader "Guten Tag"
# Rumantsch Grischun (official standard)
python3 unified_translator.py de rm-rumgr "Guten Tag"
```
---
## π Dataset Information
### Downloaded Dataset
**Location**: `datasets/romansh/` (created on demand; not redistributed β see the licence note below)
| Dataset | Language Pair | Size | Source |
|---------|--------------|------|--------|
| swiss-ai/apertus-posttrain-romansh | German β Romansh | 46,092 pairs | HuggingFace |
### Dataset Structure
```python
from datasets import load_from_disk
dataset = load_from_disk("./datasets/romansh")
print(len(dataset['train'])) # 46,092 examples
# Sample entry
sample = dataset['train'][0]
# Contains: German text β Romansh translation
```
### Dataset Contents
- **Dictionary translations**: Single words and phrases
- **Sentence-level translations**: Complete sentences
- **Idiom identification**: Romansh idioms and expressions
- **Instruction data**: Small set of human-translated instructions
---
## π§ Fine-tuning Guide (Optional)
If you want to **improve** translation quality for specific domains:
### When to Fine-tune
- β
You have domain-specific terminology (medical, legal, technical)
- β
You want better accuracy for specific Romansh variants
- β
You have additional parallel data
- β Current quality is already good for general use
### Fine-tuning Apertus-8B
**Note**: Apertus-8B is already pre-trained on Romansh data, so fine-tuning is optional.
```bash
# Using your existing training infrastructure
cd TraductAL-v1.1.0
# Fine-tune the causal LM on the Romansh dataset
# (training scripts for Apertus-8B are not included in this release)
```
**Requirements**:
- GPU with sufficient VRAM for 8B-parameter fine-tuning
- 2-6 hours training time
---
## π Troubleshooting
### Issue: "Model not found"
**Solution**: check the HuggingFace cache and pre-download if needed:
```bash
python3 startup_check.py
# or force a download:
python3 -c "from huggingface_hub import snapshot_download; snapshot_download('swiss-ai/Apertus-8B-2509')"
```
### Issue: "Translation is slow"
**Cause**: Apertus-8B runs on CPU (8B parameters)
**Solutions**:
1. **Use GPU** (if available):
- Automatically detected if CUDA available
- ~5x speedup
2. **Reduce input length**: translate paragraph by paragraph rather than whole documents
### Issue: "Virtual environment not found"
**Solution**: Activate manually:
```bash
cd TraductAL-v1.1.0
source .venv/bin/activate
python unified_translator.py de rm-sursilv "Test"
```
### Issue: "datasets library not found"
**Solution**: Already installed! If issues persist:
```bash
source .venv/bin/activate
pip install datasets
```
### Issue: "Translation quality is poor"
**Solutions**:
1. **Try different Romansh variants**:
- Each variant has different training data
- Sursilvan (`rm-sursilv`) is most common
2. **Use more context**:
- Provide full sentences instead of single words
- Include punctuation
3. **Consider fine-tuning**:
- Add domain-specific data
- See Fine-tuning Guide above
---
## π Python API Reference
### UnifiedTranslator Class
```python
from unified_translator import UnifiedTranslator
translator = UnifiedTranslator()
# Translate with auto engine selection
result = translator.translate(
text="Guten Tag",
src_lang="de",
tgt_lang="rm-sursilv"
)
# Force specific engine
result = translator.translate(
text="Hello",
src_lang="en",
tgt_lang="de"
)
# Result structure
{
"translation": "Bun di",
"model": "Apertus-8B",
"engine": "Apertus-8B",
"time": "12.30s",
"src_lang": "de (German)",
"tgt_lang": "rm-sursilv (Romansh Sursilvan)",
"device": "cpu"
}
```
### ApertusTranslator Class (Direct)
```python
from apertus_translator import ApertusTranslator
translator = ApertusTranslator()
result = translator.translate(
text="Guten Tag",
src_lang="de",
tgt_lang="rm-sursilv",
max_tokens=512
)
# List supported languages
translator.list_languages()
```
### Apertus Translator Class (Direct)
```python
from apertus_translator import ApertusTranslator
translator = ApertusTranslator()
result = translator.translate(
text="Hello",
src_lang="en",
tgt_lang="de"
)
```
---
## π Language Code Reference
### Common Source Languages
| Code | Language | Example |
|------|----------|---------|
| `de` | German | Guten Tag |
| `en` | English | Hello |
| `fr` | French | Bonjour |
| `it` | Italian | Buongiorno |
### Romansh Target Languages
| Code | Variant | Example Translation |
|------|---------|-------------------|
| `rm-sursilv` | Sursilvan | Bun di |
| `rm-vallader` | Vallader | Bun dΓ |
| `rm-puter` | Puter | Bun dì |
| `rm-rumgr` | Rumantsch Grischun | Bun di |
---
## π Support & Resources
### File Locations
```
TraductAL/
βββ unified_translator.py # Main CLI / UnifiedTranslator class
βββ apertus_translator.py # Apertus-8B wrapper
βββ translate_enhanced.sh # Shell wrapper
βββ scripts/
β βββ download_romansh_dataset.py
βββ datasets/
βββ romansh/ # Downloaded dataset (not redistributed)
Apertus-8B weights are cached under ~/.cache/huggingface/hub
(models--swiss-ai--Apertus-8B-2509) and are not shipped with the source.
```
### Documentation
- **TraductAL**: `README.md`
- **Romansh**: `ROMANSH_GUIDE.md` (this file)
### External Resources
- **Apertus-8B**: https://huggingface.co/swiss-ai/Apertus-8B-2509
- **Romansh Dataset**: https://huggingface.co/datasets/swiss-ai/apertus-posttrain-romansh
---
## β
Summary
You now have a **complete Romansh translation system** that:
β
Translates German/English/French β Romansh (all variants)
β
Automatically selects the best engine
β
Supports 1,811 languages total
β
Includes 46,092 German-Romansh training examples
β
Works 100% offline
β
Respects privacy (no data sent to external servers)
**Main command**:
```bash
cd TraductAL-v1.1.0
python3 unified_translator.py de rm-sursilv "Guten Tag"
```
**Enjoy translating!** π¨π
|