Zyroxx66/somali-nllb-specialist-481m
1
library_name: transformers tags:
- translation
- somali
- nllb
- peft
- lora
- somali_translator license: mit language:
- so
- en basemodel: AfriNLP/AfriNLLB-12enc-4dec-iterative-481m-ft pipelinetag: translation --- ***
Somali NLLB Specialist (481M)
This is a high-performance Somali translation adapter for the AfriNLLB-200 481M architecture. While the base model was iteratively pruned (which severely damaged its Somali capabilities), this specialist adapter restores and enhances its reasoning through Knowledge Distillation.
The model was trained on ~52,000 high-quality bidirectional Somali-English paragraphs. The English side of the dataset was synthetically generated using a "Teacher" model (AfriNLLB-12enc-12dec-full-ft-kd) to ensure the highest possible semantic alignment.
📊 Benchmark Comparison
This model was tested against the base 481M model across 5 distinct domains.
🛠️ Key Improvements
- Vocabulary Fixes: Corrects famous NLLB errors like translating "Park" as "Meat" (Hilibka).
- Stability: Base-model stuttering and infinite loops (e.g., "sabti sabti sabti") have been reduced by over 90%. While not 100% eliminated, the model is significantly more stable for long-form paragraph translation.
- Technical Depth: Improved handling of IT, Medical, and Scientific terminology through the Distillation process from a larger teacher model.
🚀 How to Run (Optimized for 2GB VRAM)
This model is designed to run locally on consumer hardware like a GTX 1050 (ZYROXX).
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, BitsAndBytesConfig
from peft import PeftModel
model_id = "AfriNLP/AfriNLLB-12enc-4dec-iterative-481m-ft"
adapter_id = "Zyroxx66/somali-nllb-specialist-481m"
# 1. Load with 4-bit quantization to save VRAM
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_quant_type="nf4"
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
base_model = AutoModelForSeq2SeqLM.from_pretrained(model_id, quantization_config=bnb_config, device_map="auto")
# 2. Attach the Specialist Adapter
model = PeftModel.from_pretrained(base_model, adapter_id)
def translate(text, direction="en-so"):
if direction == "en-so":
tokenizer.src_lang, tgt_lang = "eng_Latn", "som_Latn"
else:
tokenizer.src_lang, tgt_lang = "som_Latn", "eng_Latn"
inputs = tokenizer(text, return_tensors="pt").to("cuda")
outputs = model.generate(
**inputs,
forced_bos_token_id=tokenizer.convert_tokens_to_ids(tgt_lang),
max_length=256,
num_beams=5
)
return tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
print(translate("Advanced persistent threats often utilize zero-day vulnerabilities."))📈 Training Details
- Rows: 52,413 (Bidirectional)
- Epochs: 2 (Stage 1 + Stage 2)
- Rank (r): 32
- Target Modules: all-linear
- Hardware: Tesla T4
