ضبط نموذج Hugging Face دقيقًا
كيّف Transformer مدرَّبًا مسبقًا مع بياناتك
ضبط نموذج Hugging Face دقيقًا درس مجاني في Deep Learning Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Deep Learning Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
A Hub of Pretrained Models
Hugging Face hosts thousands of ready-to-use transformers for text, vision, and audio. You can fine-tune one on your own data in minutes. 🤗
Install Transformers
The transformers library gives you models, tokenizers, and training tools in one package.
pip install transformers datasetsLoad a Tokenizer
Text must become numbers first. The tokenizer that ships with each model knows exactly how to split and encode your text.
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained('bert-base-uncased')Load a Model With a New Head
Pick a class for your task. AutoModelForSequenceClassification loads the backbone and attaches a fresh classifier head for your labels.
from transformers import AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=2)Tokenize Your Dataset
Run every example through the tokenizer with padding and truncation so all inputs share the same length.
def encode(b):
return tok(b['text'], truncation=True, padding='max_length')TrainingArguments
TrainingArguments bundles your hyperparameters: learning rate, batch size, epochs, and where to save checkpoints.
from transformers import TrainingArguments
args = TrainingArguments(output_dir='out', learning_rate=2e-5, num_train_epochs=3)Keep That Rate Low
Notice the rate is just 2e-5. As with any fine-tune, a small learning rate protects the pretrained weights from being wrecked.
The Trainer
The Trainer class wraps the whole loop: forward pass, loss, backward, step, and evaluation. You skip writing it by hand.
from transformers import Trainer
trainer = Trainer(model=model, args=args, train_dataset=train_ds)Train in One Call
Once everything is wired up, kick off fine-tuning with a single train call and watch the loss fall.
trainer.train()Evaluate and Predict
After training, call evaluate for metrics on held-out data, then use predict to score brand-new examples.
trainer.evaluate()Save and Share
Persist your tuned model with save_pretrained, then reload it anywhere or push it to the Hub for others to use.
model.save_pretrained('my-classifier')Quick Check
Which Hugging Face class runs the full training loop for you so you don't write it by hand?
Recap
You tokenized data, loaded a model with a fresh head, set a low rate in TrainingArguments, and fine-tuned it with the Trainer. 🎯
الأسئلة الشائعة
هل درس «ضبط نموذج Hugging Face دقيقًا» مجاني؟
نعم — نص درس «ضبط نموذج Hugging Face دقيقًا» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Deep Learning Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.
ماذا ستتعلم في «ضبط نموذج Hugging Face دقيقًا»؟
كيّف Transformer مدرَّبًا مسبقًا مع بياناتك تتمرن على Deep Learning Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Deep Learning Academy؟
لا تُشترط خبرة سابقة. Deep Learning Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «ضبط نموذج Hugging Face دقيقًا»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Deep Learning Academy هذا؟
نعم. كل درس في Deep Learning Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- جمّد Backbone ودرّب Head
- الضبط الدقيق بمعدل تعلّم أقل
- معدلات تمييزية حسب الطبقة
- ضبط نموذج Hugging Face دقيقًا