Downloads · 30 days
51
6% of all-time downloads
ameer4wisam/gemma-iraqi-finetune
gemma-iraqi-finetune is a machine learning model from ameer4wisam. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft. The card lists the license as gemma.
هذا النموذج هو نسخة محسّنة (Fine-tuned) من نموذج google/gemma-4-12B-it، تم تدريبه خصيصاً لفهم والتحدث بـ اللهجة العراقية باستخدام تقنية LoRA (Low-Rank Adaptation).
Downloads · 30 days
51
6% of all-time downloads
All-time downloads
846
Public
Parameters
12B
67 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors24.4 GB · 100%
How the weights are stored.
BF1612B · 99%
From the Hugging Face model README
هذا النموذج هو نسخة محسّنة (Fine-tuned) من نموذج google/gemma-4-12B-it، تم تدريبه خصيصاً لفهم والتحدث بـ اللهجة العراقية باستخدام تقنية LoRA (Low-Rank Adaptation).
cosine وإحماء 3%
الكود أدناه يوضح كيفية تحميل النموذج واستخدامه للمحادثات، مع الحفاظ على الذاكرة عبر السياق الطويل وضبط الشخصية باستخدام الـ System Prompt.
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
from peft import PeftModel
# 1. تحميل النموذج الأساسي والمحوّل (Adapter)
base_model_id = "google/gemma-4-12B-it"
adapter_model_id = "ameer4wisam/gemma-iraqi-finetune"
base_model = AutoModelForCausalLM.from_pretrained(
base_model_id,
device_map="auto",
torch_dtype=torch.bfloat16
)
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
model = PeftModel.from_pretrained(base_model, adapter_model_id)
# 2. تحديد ثوابت التوقف (لمنع الهلوسة)
stop_ids = [106, 1] # <turn|> و <eos>
PAD_ID = tokenizer.pad_token_id if tokenizer.pad_token_id is not None else stop_ids[0]
# 3. إعدادات التوليد (Generation Config)
GEN_BALANCED = dict(
max_new_tokens=64,
do_sample=True,
temperature=0.3,
top_p=0.8,
top_k=20,
)
# 4. التوجيه (System Prompt)
IRAQI_SYSTEM_PROMPT = """
أنت بائع عراقي محترف
قواعد صارمة قبل كل رد:
1. راجع كلامك بعقلك قبل ما تكتبه: هل كل كلمة عراقية صحيحة وموجودة فعلاً باللهجة؟ لا تخترع كلمات.
2. استخدم مفردات عراقية أصيلة: شنو، شلون، هسه، اكو، ماكو، زين، خوش، هواي، شكد، چا، هيچي.
3. جاوب قصير ومباشر مثل البائع الحقيقي، جملة أو جملتين بس.
4. إذا ذكرت سعر أو رقم بالمحادثة، التزم بيه ولا تغيره بالأدوار الجاية.
5. تذكر تفاصيل الزبون (اسمه، شنو يريد) واستعملها بردودك.
6. إذا ما تعرف معلومة، گول "أتأكدلك" ولا تخترع جواب.
7. بِع فقط المنتجات المذكورة بالقائمة أعلاه. إذا الزبون طلب منتج مو موجود بالقائمة (مثلاً ثلاجة والقائمة كلها مكيفات)، گله بصراحة: "والله هذا ماكو عدنا هسه" واعرض عليه البديل الموجود إذا مناسب.
"""
# 5. دالة الاستدلال الأساسية
def chat(messages):
enc = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt",
return_dict=True,
)
input_ids = enc["input_ids"].to(model.device)
attention_mask = enc["attention_mask"].to(model.device)
with torch.no_grad():
out = model.generate(
input_ids=input_ids,
attention_mask=attention_mask,
eos_token_id=stop_ids,
pad_token_id=PAD_ID,
**GEN_BALANCED,
)
reply = tokenizer.decode(
out[0][input_ids.shape[1]:],
skip_special_tokens=True,
).strip()
return reply
# 6. دالة المحادثة الطويلة
def run_long_conversation(user_turns):
messages = [{"role": "system", "content": IRAQI_SYSTEM_PROMPT}]
for turn in user_turns:
messages.append({"role": "user", "content": turn})
reply = chat(messages)
messages.append({"role": "assistant", "content": reply})
print(f"👤: {turn}
🤖: {reply}
--- ")
# === تجربة الاستدلال ===
run_long_conversation([
"هلو، اسمي أبو علي وأدور على ثلاجة",
"شنو الأحجام الموجودة؟",
"طيب، تتذكر شنو اسمي وشنو كنت أدور؟"
])