Llama-ArabicSci-SFT-75M
Llama-ArabicSci-SFT-75M is a Supervised Fine-Tuned (SFT) adaptation of AtheerSky/Llama-ArabicSci-70M (~75M parameters). It uses Domain-Aligned Synthetic Instruction Tuning on AtheerSky/ArabicSci_Story to adapt the base language model into an Arabic assistant capable of generating children's stories and sharing simplified scientific facts upon request.
1. Model & Adaptation Details
- Base Model: AtheerSky/Llama-ArabicSci-70M (Llama architecture, 18 layers, hidden size 512, 8 attention heads, 4 KV heads, vocab size 8,194)
- Fine-Tuning Method: Full-parameter Supervised Fine-Tuning (SFT) with prompt loss masking (
-100on user prompt tokens; loss computed strictly on assistant response tokens) - Chat Template:
<bos><|user|>{prompt}<|assistant|>{response}<eos> - Dataset: 4,216 domain-aligned Arabic instruction-response pairs (
3,916train /300validation) derived from AtheerSky/ArabicSci_Story, covering story generation requests and simplified science Q&A - Training Setup:
366optimizer updates (3epochs,lr=1e-4, cosine schedule,batch_size=32, ~8 minutes on NVIDIA T4 GPU)
2. Evaluation Results
- Validation Loss (Answer Tokens): Dropped from 2.950 (before SFT) to 2.603 (
Perplexity: 13.5) - Final Training Loss:
2.279(closely aligned with validation loss, confirming strong generalization with no overfitting) - Qualitative Improvement: Unlike the base model (which jumped straight to story endings), the SFT model follows instructions properly—generating complete Arabic stories from the beginning when asked for a story, and providing clear, accurate science facts when asked for scientific information.
3. Limitations
- Topic Matching in Short Prompts: While the model reliably distinguishes between story requests and science-fact requests, its compact capacity (~75M parameters) means it occasionally retrieves a general science fact rather than matching the exact keyword in a specific question.
4. Usage Example
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "AtheerSky/Llama-ArabicSci-SFT-75M"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
model.eval()
question = "اكتب لي قصة أطفال قصيرة وممتعة."
prompt = f"<bos><|user|>{question}<|assistant|>"
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=140,
do_sample=True,
temperature=0.7,
top_k=40,
repetition_penalty=1.2,
pad_token_id=tokenizer.pad_token_id,
eos_token_id=tokenizer.eos_token_id,
)
full_text = tokenizer.decode(outputs[0], skip_special_tokens=False)
answer = full_text.split("<|assistant|>")[-1].replace("<eos>", "").replace("<pad>", "").strip()
print(answer)