Instructions to use zcgf111/linguaforge-gemma4-204lang-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use zcgf111/linguaforge-gemma4-204lang-lora with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/gemma-4-e4b-it-unsloth-bnb-4bit") model = PeftModel.from_pretrained(base_model, "zcgf111/linguaforge-gemma4-204lang-lora") - Notebooks
- Google Colab
- Kaggle
Add README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-sa-4.0
|
| 3 |
+
base_model: google/gemma-4-E4B-it
|
| 4 |
+
library_name: peft
|
| 5 |
+
tags:
|
| 6 |
+
- lora
|
| 7 |
+
- gemma-4
|
| 8 |
+
- multilingual
|
| 9 |
+
- low-resource-languages
|
| 10 |
+
- endangered-languages
|
| 11 |
+
language:
|
| 12 |
+
- multilingual
|
| 13 |
+
datasets:
|
| 14 |
+
- facebook/flores
|
| 15 |
+
- shiyue/chr_en
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# LinguaForge — Gemma 4 E4B LoRA across 204 languages
|
| 19 |
+
|
| 20 |
+
A single ~170 MB LoRA adapter that shifts Google DeepMind's
|
| 21 |
+
[`google/gemma-4-E4B-it`](https://huggingface.co/google/gemma-4-E4B-it)
|
| 22 |
+
toward every language in **FLORES-200** (Meta NLLB Team, *No Language Left
|
| 23 |
+
Behind*, Nature 2024) plus Cherokee depth from the **ChrEn** corpus
|
| 24 |
+
(Zhang, Frey & Bansal, EMNLP 2020). Cherokee is *not* in FLORES-200.
|
| 25 |
+
|
| 26 |
+
Trained as part of the **LinguaForge / 古韵 GuYun** submission to the
|
| 27 |
+
Gemma 4 Hackathon (`AI for Good — endangered language preservation`).
|
| 28 |
+
|
| 29 |
+
## Training summary (Kaggle T4, ~5 h 9 min)
|
| 30 |
+
|
| 31 |
+
| | |
|
| 32 |
+
|---|---|
|
| 33 |
+
| Base model | `unsloth/gemma-4-e4b-it-unsloth-bnb-4bit` (4-bit NF4) |
|
| 34 |
+
| Trainable params | 42,401,792 / 8,038,558,240 (0.53%) |
|
| 35 |
+
| Target modules | `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj` |
|
| 36 |
+
| Rank / alpha / dropout | 16 / 32 / 0.05 |
|
| 37 |
+
| Total chat samples | 33,480 (alt. `en → target` / `target → en`) |
|
| 38 |
+
| Languages covered | **203 FLORES-200 languages + Cherokee from ChrEn = 204** |
|
| 39 |
+
| Continents | 6 (Africa, Asia, Europe, Pacific, South America, Diaspora) + N. America |
|
| 40 |
+
| Optimizer steps | 8,370 (1 epoch, batch 2 × grad-accum 2) |
|
| 41 |
+
| Reproducer | Kaggle kernel [`dongwei666/linguaforge-auto`](https://www.kaggle.com/code/dongwei666/linguaforge-auto) |
|
| 42 |
+
|
| 43 |
+
## Held-out evaluation (FLORES-200 devtest + ChrEn seed=99)
|
| 44 |
+
|
| 45 |
+
Numbers from Kaggle kernel
|
| 46 |
+
[`dongwei666/linguaforge-eval`](https://www.kaggle.com/code/dongwei666/linguaforge-eval),
|
| 47 |
+
50 unseen sentences per language, greedy decoding, `sacrebleu` corpus-level
|
| 48 |
+
metrics.
|
| 49 |
+
|
| 50 |
+
| Language | base BLEU | +LoRA BLEU | Δ BLEU | base chrF | +LoRA chrF | Δ chrF |
|
| 51 |
+
|---|---:|---:|---:|---:|---:|---:|
|
| 52 |
+
| Cherokee (`chr_Cher`) | 0.04 | **0.45** | +0.41 | 2.30 | **7.87** | **+5.56** (3.4×) |
|
| 53 |
+
| Tibetan (`bod_Tibt`) | 0.12 | **0.21** | +0.09 | 19.14 | **27.05** | **+7.91** |
|
| 54 |
+
| Welsh (`cym_Latn`) | 3.90 | **6.13** | **+2.23** | 31.11 | 31.21 | +0.10 |
|
| 55 |
+
| Quechua (`quy_Latn`) | 1.02 | **1.93** | +0.91 | 19.94 | **22.49** | +2.55 |
|
| 56 |
+
| Māori (`mri_Latn`) | 3.64 | **4.16** | +0.52 | 28.48 | 27.58 | −0.90 |
|
| 57 |
+
| Yoruba (`yor_Latn`) | 2.54 | 1.12 | −1.42 | 21.65 | 11.10 | −10.55 ⚠ |
|
| 58 |
+
| **Mean (6 langs)** | **1.88** | **2.33** | **+0.45** | **20.44** | **21.22** | **+0.78** |
|
| 59 |
+
|
| 60 |
+
Honest read: the LoRA's biggest wins are on **languages whose scripts the
|
| 61 |
+
base model could barely write** (Cherokee chrF 3.4×, Tibetan chrF +7.91).
|
| 62 |
+
Welsh shows the largest BLEU jump (+2.23) — the adapter strips a
|
| 63 |
+
`**Welsh Translation:**` boilerplate prefix from the base model. Yoruba
|
| 64 |
+
regressed into a repetition loop; reported transparently. With more
|
| 65 |
+
samples per language or per-community LoRAs, that regression should
|
| 66 |
+
resolve.
|
| 67 |
+
|
| 68 |
+
## Usage
|
| 69 |
+
|
| 70 |
+
```python
|
| 71 |
+
from unsloth import FastLanguageModel
|
| 72 |
+
from unsloth.chat_templates import get_chat_template
|
| 73 |
+
import torch
|
| 74 |
+
|
| 75 |
+
model, tok = FastLanguageModel.from_pretrained(
|
| 76 |
+
model_name="zcgf111/linguaforge-gemma4-204lang-lora",
|
| 77 |
+
max_seq_length=2048,
|
| 78 |
+
load_in_4bit=True,
|
| 79 |
+
)
|
| 80 |
+
tok = get_chat_template(tok, chat_template="gemma")
|
| 81 |
+
FastLanguageModel.for_inference(model)
|
| 82 |
+
|
| 83 |
+
msgs = [
|
| 84 |
+
{"role": "system", "content": "You are LinguaForge, a multilingual tutor for endangered and low-resource languages."},
|
| 85 |
+
{"role": "user", "content": "Translate this English sentence into Maori (Polynesian, Pacific):\n\nHello, my name is Sarah."},
|
| 86 |
+
]
|
| 87 |
+
text = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
|
| 88 |
+
inputs = tok.tokenizer(text, return_tensors="pt").to(model.device)
|
| 89 |
+
with torch.inference_mode():
|
| 90 |
+
out = model.generate(**inputs, max_new_tokens=128, do_sample=False,
|
| 91 |
+
pad_token_id=tok.tokenizer.eos_token_id)
|
| 92 |
+
print(tok.tokenizer.decode(out[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
## Citations
|
| 96 |
+
|
| 97 |
+
```bibtex
|
| 98 |
+
@article{nllb2024,
|
| 99 |
+
title={Scaling neural machine translation to 200 languages},
|
| 100 |
+
author={{NLLB Team} and Costa-juss{\`a}, Marta R. and others},
|
| 101 |
+
journal={Nature},
|
| 102 |
+
year={2024},
|
| 103 |
+
doi={10.1038/s41586-024-07335-x}
|
| 104 |
+
}
|
| 105 |
+
@inproceedings{zhang-etal-2020-chren,
|
| 106 |
+
title={{ChrEn}: {Cherokee-English} Machine Translation for Endangered Language Revitalization},
|
| 107 |
+
author={Zhang, Shiyue and Frey, Benjamin and Bansal, Mohit},
|
| 108 |
+
booktitle={EMNLP},
|
| 109 |
+
year={2020}
|
| 110 |
+
}
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
## License
|
| 114 |
+
|
| 115 |
+
CC-BY-SA 4.0, matching the FLORES-200 license. ChrEn is released
|
| 116 |
+
under CC-BY-SA 4.0 by its authors.
|