Views
No views yet
| Property | Value |
|---|---|
| Base Model | google/gemma-3-12b-it |
| Translation Direction | Amharic → English |
| LoRA Rank (r) | 8 |
| LoRA Alpha | 16 |
| Training Method | QLoRA (4-bit quantization) |
| Domain | Scientific/Academic texts |
1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5# Configure 4-bit quantization (recommended for memory efficiency)
6bnb_config = BitsAndBytesConfig(
7 load_in_4bit=True,
8 bnb_4bit_compute_dtype=torch.bfloat16,
9 bnb_4bit_quant_type="nf4",
10 bnb_4bit_use_double_quant=True,
11)
12
13# Load base model
14base_model = AutoModelForCausalLM.from_pretrained(
15 "google/gemma-3-12b-it",
16 quantization_config=bnb_config,
17 device_map="auto",
18 torch_dtype=torch.bfloat16,
19)
20tokenizer = AutoTokenizer.from_pretrained("google/gemma-3-12b-it")
21
22# Load LoRA adapter
23adapter_name = "dsfsi/gemma_3_12b_it-lora-r8-amh-eng"
24model = PeftModel.from_pretrained(base_model, adapter_name)
25model.eval()
26
27# Prepare translation prompt
28source_text = "Climate change significantly impacts agricultural productivity in sub-Saharan Africa."
29instruction = "Translate the following Amharic scientific text to English."
30
31# Format for Gemma chat template
32messages = [{"role": "user", "content": f"{instruction}\n\n{source_text}"}]
33prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
34
35# Generate translation
36inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
37with torch.no_grad():
38 outputs = model.generate(
39 **inputs,
40 max_new_tokens=256,
41 num_beams=5,
42 early_stopping=True,
43 pad_token_id=tokenizer.pad_token_id,
44 )
45
46# Decode only the generated part
47generated = outputs[0][inputs["input_ids"].shape[1]:]
48translation = tokenizer.decode(generated, skip_special_tokens=True)
49print(translation)1# For GPUs with sufficient memory (>24GB for larger models)
2base_model = AutoModelForCausalLM.from_pretrained(
3 "google/gemma-3-12b-it",
4 device_map="auto",
5 torch_dtype=torch.bfloat16,
6)
7model = PeftModel.from_pretrained(base_model, "dsfsi/gemma_3_12b_it-lora-r8-amh-eng")| Configuration | VRAM Required |
|---|---|
| 4-bit (QLoRA) | ~8-12 GB |
| 8-bit | ~16-20 GB |
| Full precision | ~24-40 GB |
1# Clone the AfriScience-MT repository
2git clone https://github.com/afriscience-mt/afriscience-mt.git
3cd afriscience-mt
4
5# Install dependencies
6pip install -r requirements.txt
7
8# Run LoRA training
9python -m afriscience_mt.scripts.run_lora_training \
10 --data_dir ./data \
11 --source_lang amh \
12 --target_lang eng \
13 --model_name google/gemma-3-12b-it \
14 --model_type gemma \
15 --lora_rank 8 \
16 --output_dir ./output \
17 --num_epochs 3 \
18 --batch_size 4 \
19 --load_in_4bit1@article{abdulmumin2026afriscience,
2 title = {AfriScience-MT: Towards Decolonizing Science in Africa through Text Translation},
3 author = {Abdulmumin, Idris and Gwadabe, Tajuddeen and Muhammad, Shamsuddeen Hassan and Adelani, David Ifeoluwa and Khalo, Nomonde and Ahmad, Ibrahim Said and Modupe, Abiodun and Mumm, Anina and Biyela, Sibusiso and Rabie, Michelle and Havemann, Johanna and Rei, Marek and Abbott, Jade and Marivate, Vukosi},
4 journal = {arXiv preprint arXiv:2605.29741},
5 year = {2026},
6 url = {https://arxiv.org/abs/2605.29741}
7}