|
Download docs/ROMANSH_GUIDE.md from Norelad/TraductAL: direct link, hf CLI and curl.
- Browser
- Download file 10 kB
-
https://huggingface.co/spaces/Norelad/TraductAL/resolve/main/docs/ROMANSH_GUIDE.md
- Command line
-
hf download hf://spaces/Norelad/TraductAL/docs/ROMANSH_GUIDE.md
-
curl -L -o ROMANSH_GUIDE.md https://huggingface.co/spaces/Norelad/TraductAL/resolve/main/docs/ROMANSH_GUIDE.md
10 kB
| # 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!** π¨π | |