CoolFace
Modelpublic

Zyroxx66/somali-nllb-specialist-481m

sourceHugging Facemitupdated 5mo agoView on Hugging Face
1likes
Model Card

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.

DomainEnglish SourceBase NLLB (481M)Specialist Adapter (Ours)
Medical"Could you please help me find the nearest hospital? It's an emergency."Ma caawin kartid in aad ii caawiso in aan helno isbitaalka ugu dhow?Fadlan ma i caawin kartaa inaan helo isbitaalka ugu dhow? Waa xaalad degdeg ah.
Social"I am sorry, I can't come to your party on Saturday because I have to work."...ma imaan karo caashaada sabtida sabti sabti...Waan ka xumahay, ma iman karo xafladdaada Sabtida... waa inaan shaqeeyo.
Tech"My phone is broken and the screen is not working..."Telefoonkeyga ayaa burburay... Ma ogow meesha...?Telefoonkaydu waa la jebiyey... Ma ogtaa meesha...?
Logic"The weather is very nice today, let's go for a walk in the park."...aan ku soconno hilibka (meat)....aan ku tagno socodka beerta (park).
Science"The Earth orbits the sun once every 365 days..."Dhulku wuxuu wareegaa qorraxda... (Stutters on days)Dhulku wuxuu ku wareegaa qorraxda... taas oo abuurta afarta xilli.

🛠️ 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).

python
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