huggingface-gemma-recipes
هو مشروع مفتوح المصدر تتم صيانته رسميًا بواسطة Hugging Face، ويهدف إلى تزويد المستخدمين بأمثلة تعليمات برمجية ودروس تعليمية مبسطة تتعلق بنماذج Google Gemma. الهدف الأساسي للمشروع هو مساعدة المطورين على البدء بسرعة في استنتاج نماذج Gemma وضبطها الدقيق ومختلف سيناريوهات التطبيق العملي.
يدعم هذا المشروع قدرات الوسائط المتعددة لسلسلة نماذج Gemma 3:
يوفر المشروع واجهة استنتاج نموذج موحدة، تدعم التحميل السريع واستخدام نماذج Gemma:
from transformers import AutoProcessor, AutoModelForImageTextToText
import torch
model_id = "google/gemma-3n-e4b-it" # أو google/gemma-3n-e2b-it
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForImageTextToText.from_pretrained(model_id).to(device)
def model_generation(model, messages):
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
)
input_len = inputs["input_ids"].shape[-1]
inputs = inputs.to(model.device, dtype=model.dtype)
with torch.inference_mode():
generation = model.generate(**inputs, max_new_tokens=32, disable_compile=False)
generation = generation[:, input_len:]
decoded = processor.batch_decode(generation, skip_special_tokens=True)
print(decoded[0])
# سؤال وجواب نصي
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": "What is the capital of France?"}
]
}
]
model_generation(model, messages)
# تحويل الكلام إلى نص
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": "Transcribe the following speech segment in English:"},
{"type": "audio", "audio": "https://huggingface.co/datasets/ariG23498/demo-data/resolve/main/speech.wav"},
]
}
]
model_generation(model, messages)
# وصف الصورة
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "https://huggingface.co/datasets/ariG23498/demo-data/resolve/main/airplane.jpg"},
{"type": "text", "text": "Describe this image."}
]
}
]
model_generation(model, messages)
يوفر المشروع العديد من خطط وبرامج الضبط الدقيق:
# تثبيت التبعيات
$ pip install -U -q -r requirements.txt
# تثبيت التبعيات الأساسية
$ pip install -U -q transformers timm
# تثبيت التبعيات الكاملة (للضبط الدقيق)
$ pip install -U -q -r requirements.txt
huggingface-gemma-recipes/
├── notebooks/ # دروس دفتر Jupyter
│ └── fine_tune_gemma3n_on_t4.ipynb
├── scripts/ # برامج الضبط الدقيق
│ ├── ft_gemma3n_image_vt.py
│ ├── ft_gemma3n_audio_vt.py
│ └── ft_gemma3n_image_trl.py
├── requirements.txt # قائمة التبعيات
└── README.md # وصف المشروع
يتمتع هذا المشروع، باعتباره مشروعًا مفتوح المصدر تتم صيانته رسميًا بواسطة Hugging Face، بالمزايا التالية:
huggingface-gemma-recipes
هو مشروع مفتوح المصدر عالي الجودة يوفر حلاً كاملاً لاستخدام نماذج Gemma. سواء كنت مبتدئًا أو مطورًا متمرسًا، يمكنك العثور على الموارد والإرشادات المناسبة. إن دعم المشروع للوسائط المتعددة وخطط الضبط الدقيق المرنة تجعله أحد الأدوات المهمة في مجال تطوير الذكاء الاصطناعي الحالي.