كيف تُدرَّب LLMs
تعرّفوا إلى مراحل تدريب LLMs: التدريب المسبق على مجموعات نصية ضخمة، والضبط الدقيق الخاضع للإشراف، وRLHF، واكتشفوا أهمية كل مرحلة في سلوك النموذج.
كيف تُدرَّب LLMs درس مجاني في AI Engineering Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في AI Engineering Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة AI Engineering Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Three Stages of LLM Training
LLMs are built in three stages: pre-training teaches language and knowledge, fine-tuning teaches instruction-following, and RLHF aligns the model with what people want.
Pre-Training: Next Token Prediction at Scale
Pre-training feeds the model tons of text with one job: predict the next token. That simple goal is enough to teach grammar, facts, and reasoning along the way.
Training Data Quality and Curation
Raw internet text is messy. Teams clean it with data pipelines that filter, deduplicate, and score quality. The rule of thumb: better data beats a bigger model.
The Loss Function and Optimization
Training minimizes cross-entropy loss — how far the model's guess is from the right next token. Tiny weight nudges, repeated billions of times. The code shows the math.
# Illustrative cross-entropy loss for a single token prediction
import math
vocab_size = 50000
correct_token_index = 4217 # index for the word 'Paris'
# Model output probabilities (softmax of logits)
model_probs = [0.00002] * vocab_size # simplified uniform base
model_probs[correct_token_index] = 0.70 # model is 70% confident in 'Paris'
loss = -math.log(model_probs[correct_token_index])
print(f'Cross-entropy loss: {loss:.4f}') # ~0.3567Emergent Capabilities from Scale
At enough scale, new emergent capabilities appear — like step-by-step reasoning — that small models simply don't have. Nobody trained them in directly; scale brought them.
Supervised Fine-Tuning on Instruction Pairs
A raw model just continues text. Supervised fine-tuning trains it on (instruction, ideal answer) pairs, so it learns to actually answer instead of rambling on.
# Illustrative SFT data format
training_example = {
'messages': [
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': 'What is the capital of France?'},
{'role': 'assistant', 'content': 'The capital of France is Paris.'}
]
}
# During SFT, loss is computed only on the assistant turn tokens
# The system and user tokens are provided as context but not trained onRLHF Phase 1: Training the Reward Model
RLHF starts with a reward model. People pick the better of two answers, and the reward model learns to predict those preferences — a stand-in for human taste.
RLHF Phase 2: PPO Fine-Tuning
Next, PPO tunes the LLM to score higher on the reward model. A KL penalty keeps it from drifting weird and gaming the reward instead of truly helping.
Direct Preference Optimization: Simpler RLHF
PPO is complex. DPO is a simpler alternative: it trains the model straight from preferred-vs-rejected answer pairs — no separate reward model needed.
Chinchilla Scaling Laws: Compute-Optimal Training
The Chinchilla finding: older models were undertrained. For a given budget, scale data and size together — roughly 20 tokens per parameter for the best results.
What Each Training Stage Affects
Each stage controls something: pre-training sets what it knows, fine-tuning sets how it behaves, and RLHF sets its values. That tells you which part to fix.
Quick Check
Test your understanding of AI Engineering concepts from this lesson.
Lesson Recap
Recap: pre-training builds knowledge, fine-tuning builds instruction-following, and RLHF or DPO aligns the model with human values. Next: what LLMs can and can't do. 💡
الأسئلة الشائعة
هل درس «كيف تُدرَّب LLMs» مجاني؟
نعم — نص درس «كيف تُدرَّب LLMs» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة AI Engineering Academy، انتقل إلى CoddyKit PRO. تتضمن دورة AI Engineering Academy 4 دروس في المجموع.
ماذا ستتعلم في «كيف تُدرَّب LLMs»؟
تعرّفوا إلى مراحل تدريب LLMs: التدريب المسبق على مجموعات نصية ضخمة، والضبط الدقيق الخاضع للإشراف، وRLHF، واكتشفوا أهمية كل مرحلة في سلوك النموذج. تتمرن على AI Engineering Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ AI Engineering Academy؟
لا تُشترط خبرة سابقة. AI Engineering Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «كيف تُدرَّب LLMs»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس AI Engineering Academy هذا؟
نعم. كل درس في AI Engineering Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- من الإكمال التلقائي إلى ChatGPT
- المحوّلات وآلية الانتباه بلغة واضحة
- كيف تُدرَّب LLMs
- إمكانات LLMs وحدودها