التعلم العميق

Transformers وLLM التطبيقات والمستقبل

Deep Learning Guide · الجزء 3 من 3

Transformers وLLM — التطبيقات والمستقبل

الجزء الأخير: Attention وTransformer (أساس ChatGPT)، نماذج اللغة الضخمة، GANs وتوليد الصور، Transfer Learning، أطر العمل، النشر، الأخلاقيات، حدود DL، ومسارك التعليمي — خاتمة شاملة للسلسلة.

✍ عبدالرحمن الرفاعي
Transformer + LLM
مسار مهني
01 Attention

Attention — آلية «الانتباه»

في ترجمة «The cat sat on the mat» → «القطة جلست على الحصيرة»: كلمة «cat» ترتبط بـ «القطة»، «mat» بـ «الحصيرة». RNN تمرّ sequentially — صعب ربط كلمات بعيدة. Attention تحلّ هذا: «إلى أي جزء من المدخل أُركّز الآن؟»

تشبيه: القراءة مع تمييز

عند ترجمة جملة، أنت «تميّز» الكلمات ذات الصلة في الأصل أثناء كتابة الترجمة. Attention = نفس الفكرة رياضيًا — أوزان لكل كلمة في المدخل تُجمّع القيم المُرجّحة.

Self-Attention

كل كلمة «تنظر» لكل الكلمات في نفس الجملة — «bank» في «river bank» vs «bank account» تفهم من السياق. Query, Key, Value — ثلاثة vectors لكل token. Attention score = softmax(Q·K^T / √d) · V.

مثال Self-Attention

جملة: «الطالب الذكي نجح» — عند معالجة «نجح»، Attention تعطي weight عالي لـ «الطالب» و«الذكي» (cause) — weight منخفض لـ «ال». النموذج «يفهم» من نجح ولماذا.

02 Transformer

Transformer — «Attention is All You Need» (2017)

ورقة Google غيّرت NLP للأبد. Transformer = Attention فقط — لا RNN، لا CNN. Parallelizable — تدريب أسرع بكثير. أساس: BERT, GPT, T5, LLaMA, Claude.

Input Embeddings Encoder Self-Attention + FFN Decoder Masked Attention + Cross-Attention Encoder-Decoder (ترجمة) — GPT: Decoder فقط
بنية Transformer: Encoder + Decoder (أو Decoder-only لـ GPT)

Encoder-only (BERT)

فهم النص — تصنيف، استخراج كيانات، Q&A. يقرأ الجملة كاملة bidirectional.

Decoder-only (GPT)

توليد النص — يتنبأ بالكلمة التالية. autoregressive — كلمة كلمة.

Encoder-Decoder (T5)

ترجمة، تلخيص — input → encoder → decoder → output.

03 LLM

نماذج اللغة الضخمة (Large Language Models)

LLM = Transformer ضخم (مليارات parameters) مدرَّب على ترabytes من النص من الإنترنت. GPT-3: 175B parameters. GPT-4: أكبر (undisclosed). LLaMA, Claude, Gemini — competitors.

كيف يعمل ChatGPT؟ (مبسّط)

  1. Pre-training: «تخمين الكلمة التالية» على تريلions tokens — يتعلّم grammar، facts، reasoning patterns.
  2. Fine-tuning: تدريب على conversations، instructions — يصبح «مساعدًا».
  3. RLHF: Reinforcement Learning from Human Feedback — humans rate responses — model learns preferences.
  4. Inference: أنت تكتب prompt → model generates token by token → response.
مثال Prompt → Response

Prompt: «اشرح التعلم العميق لطفل عمره 10 سنوات»

Internal: tokenize → embeddings → 96 layers Transformer → logits لكل token في vocabulary → sample «تخيّل» → «تخيّل دماغ» → ... → full response.

Output: «تخيّل دماغًا مصنوعًا من طبقات — كل طبقة تتعلّم شيئًا أصعب...»

هل ChatGPT «يفكّر»؟

لا. يتنبأ إحصائيًا بالكلمة الأكثر احتمالًا التالية — لا وعي، لا فهم حقيقي، لا «يعرف» أنه يخطئ. يمكن أن يهلوس (Hallucination) — يختلق حقائق بثقة. استخدمه كأداة — تحقّق من المعلومات المهمة.

مفاهيم LLM مهمة

  • Token: وحدة نص — كلمة أو جزء كلمة. «التعلم» قد = token واحد.
  • Context Window: كم token يرى — GPT-4: 128K+. يحدّ طول المحادثة.
  • Temperature: randomness — 0 = deterministic، 1+ = creative.
  • Prompt Engineering: صياغة السؤال — «chain of thought»، few-shot examples.
  • RAG: Retrieval Augmented Generation — ربط LLM بقاعدة معرفة خارجية.
04 Generative

GANs وDiffusion — توليد الصور والمحتوى

ليس كل DL = تصنيف. Generative Models ت تُنشئ بيانات جديدة — صور، موسيقى، نص.

GAN (Generative Adversarial Network)

مولّد (Generator) vs مميّز (Discriminator) — «لعبة»: Generator ي fake صور، Discriminator ي detect fake. كلاهما يتحسّن. DALL-E 2 early، StyleGAN للوجوه.

Diffusion Models

ت add noise تدريجيًا → ت learn reverse — denoise. Stable Diffusion, Midjourney, DALL-E 3. state-of-the-art للصور 2024–2026.

VAE (Variational Autoencoder)

compress → latent space → reconstruct/generate. أ less sharp من GAN لكن stable training.

Multimodal

GPT-4V, Gemini — نص + صورة + صوت. «ما في هذه الصورة؟» → vision encoder + LLM.

مثال Diffusion

Prompt: «قطة ترتدي نظارات على شاطئ عند الغروب» → Diffusion model starts من noise → 50 steps denoising → صورة 1024×1024. كل step ي refine details — fur, glasses reflection, sunset colors.

05 Transfer

Transfer Learning — لا تبدأ من الصفر

تدريب ResNet على ImageNet (1.2M صورة، 1000 فئة) يأخذ أسابيع على GPU clusters. Transfer Learning: خذ model م pre-trained → fine-tune على بياناتك (100–1000 صورة) → دقة عالية في ساعات.

خطوات Transfer Learning للصور

  1. حمّل ResNet/EfficientNet pre-trained على ImageNet.
  2. «جمد» (freeze) الطبقات الأولى — features عامة (edges, shapes).
  3. استبدل طبقة المخرج — 1000 → عدد فئاتك (مثلاً 5).
  4. درّب الطبقات الأخيرة + optionally بعض الطبقات العليا.
  5. Evaluate — غالبًا 90%+ accuracy ببيانات قليلة.
Transfer Learning للنص

BERT Arabic pre-trained → fine-tune على tweets للsentiment. GPT fine-tuning على domain-specific docs — «legal GPT». Hugging Face يوفر آلاف models جاهزة — download + fine-tune.

06 Frameworks

PyTorch وTensorFlow — أين تكتب الكود؟

الإطار المطوّر المميزات متى تستخدمه
PyTorch Meta Pythonic، dynamic graph، research-friendly المبتدئون، الأبحاث، LLM
TensorFlow Google TF Serving، TFLite (mobile)، production إنتاج scale، mobile، Google Cloud
Keras API عالي المستوى — فوق TF بداية سريعة، prototypes
JAX Google NumPy + autograd + GPU research متقدم
Hugging Face Transformers library — BERT, GPT ready NLP، LLM fine-tuning
كود PyTorch — Forward pass بسيط

import torch
import torch.nn as nn

model = nn.Sequential(
  nn.Linear(784, 128), nn.ReLU(),
  nn.Linear(128, 10)
)
x = torch.randn(32, 784) # batch of 32
output = model(x) # forward pass
loss = nn.CrossEntropyLoss()(output, labels)
loss.backward() # backprop — automatic!

نصيحة: ابدأ PyTorch + Fast.ai أو Hugging Face course — practical، less boilerplate.

07 Applications

تطبيقات التعلم العميق في العالم الحقيقي

المجال التطبيق التقنية
الصحة تشخيص أشعة، اكتشاف سرطان، drug discovery CNN, GNN
السيارات قيادة ذاتية — Tesla, Waymo CNN + LiDAR fusion
المالية كشف احتيال، trading algorithms RNN, Transformer
التجزئة توصيات Amazon، visual search Embeddings, CNN
الترفيه Netflix recommendations، deepfakes detection Matrix factorization, CNN
الزراعة كشف أمراض النبات من صور drone CNN + Transfer Learning
التعليم تخصيص تعلّم، تصحيح تلقائي، ChatGPT tutors LLM, adaptive systems
الأمن Face recognition، anomaly detection CNN, Autoencoders
08 Hardware

GPU والبنية التحتية — لماذا DL «جوعان» للقوة؟

تدريب GPT-3 cost ~$4.6M في GPU time. MNIST على CPU: دقائق. ResNet ImageNet على GPU: أيام. LLM: weeks على thousands GPUs.

GPU (NVIDIA)

Parallel matrix ops — CUDA. RTX 4090 للhobbyists. A100/H100 لل datacenters. ضروري لتدريب DL serious.

TPU (Google)

Tensor Processing Unit — optimized لل TensorFlow/JAX. Cloud TPU للtraining scale.

Cloud

AWS, GCP, Azure — rent GPU by hour. Colab/Kaggle free tier — للتعلّم. Lambda Labs, RunPod — cheaper alternatives.

بدون GPU؟

تعلّم مفاهيم + small datasets (MNIST) على CPU. للصور/LLM: Colab free GPU (T4) — 12–15 ساعة/session. أو cloud credits للطلاب (AWS Educate, GCP credits).

09 Deploy

النشر وMLOps — من Notebook إلى Production

Model في Jupyter ≠ product. MLOps = DevOps + ML — deploy، monitor، retrain.

  • Export: ONNX, TorchScript, TensorFlow SavedModel — format portable.
  • Serving: TensorFlow Serving, TorchServe, Triton — API REST/gRPC.
  • Edge: TFLite, Core ML — mobile/IoT inference.
  • Monitoring: drift detection — data يتغير → model ي degrade.
  • CI/CD for ML: automated retraining pipelines — Kubeflow, MLflow.
مثال Pipeline إنتاج

1. Data pipeline (Airflow) → 2. Train weekly (GPU cluster) → 3. Validate → 4. Deploy to Kubernetes → 5. Monitor latency/accuracy → 6. Alert if drift → 7. Retrain. Cycle مستمر.

10 Ethics

الأخلاقيات والحدود — DL ليس neutral

Bias (التحيز): model trained on biased data → biased predictions. Facial recognition أ worse على dark skin — documented. Fix: diverse data، fairness metrics، audit.
Privacy: models can memorize training data — membership inference attacks. GDPR، data minimization، federated learning.
Deepfakes: GANs/Diffusion → fake videos/audio. Misinformation، fraud. Detection models + regulation.
Jobs: automation — some jobs displaced، new jobs created (ML engineer، prompt engineer). Reskilling important.
Environment: training LLM = tons CO₂. Efficient architectures، green AI research.
Explainability: DL «black box» — LIME, SHAP for interpretability. Critical في healthcare، law.
حدود DL اليوم

لا AGI (General AI) بعد — models narrow. No true reasoning — pattern matching sophisticated. Hallucinations. Adversarial attacks (small noise → wrong class). Need lots of data. Cannot replace human judgment in high-stakes decisions.

11 Roadmap

مسارك التعليمي — من الصفر إلى ML Engineer

① Python أساسيات ② رياضيات (جبر خطي، تفاضل، احتمالات) ③ ML كلاسيكي (scikit-learn) ④ هذا الدليل — DL concepts ⑤ PyTorch + مشروع MNIST/CIFAR ⑥ CNN project (تصنيف صور) ⑦ NLP + Transformers (Hugging Face) ⑧ Kaggle competitions ⑨ Portfolio + GitHub ⑩ internship / junior ML role

موارد مجانية موصى بها

  • دورات: Fast.ai, Andrew Ng (Coursera DL), Hugging Face NLP Course, 3Blue1Brown Neural Networks (YouTube).
  • كتب: «Deep Learning» — Goodfellow (free online), «Hands-On ML» — Géron.
  • ممارسة: Kaggle, Papers With Code, Google Colab notebooks.
  • أدلة الرفاعي: AI & ML, الرياضيات للAI, الجبر الخطي.

مسارات مهنية

ML Engineer

بناء وdeploy models — Python, PyTorch, MLOps. $100K–200K+ في US.

Data Scientist

تحليل + modeling — إحصاء، visualization، ML. broader من ML Engineer.

Research Scientist

PhD غالبًا — papers، new architectures. OpenAI, DeepMind, universities.

AI Product Manager

فهم tech + business — define AI products. less coding.

12 Summary

الخاتمة — ماذا تعلّمت في هذه السلسلة؟

الجزء 1: ما هو DL، AI→ML→DL، العصبون، طبقات، Forward Pass، Activation.

الجزء 2: Training loop، Loss، Gradient Descent، Backprop، Optimizers، Regularization، CNN، RNN.

الجزء 3: Attention، Transformer، LLM، Generative models، Transfer Learning، Frameworks، Deploy، Ethics، Roadmap.

الرسالة الأخيرة

التعلم العميق أداة قوية — غيّرت العالم في decade. لكنها أداة — تحتاج بيانات جيدة، تصميم careful، ومسؤولية أخلاقية. لا تخف من الرياضيات — تعلّمها تدريجيًا. ابنِ مشاريع — أفضل teacher. المجال يتطور بسرعة — stay curious، read papers، experiment.

بالتوفيق في رحلتك — وإذا أفادك هذا الدليل، شاركه مع من يبدأ مثلك. 🚀

FAQ أسئلة

أسئلة شائعة — خاتمة السلسلة

PyTorch أم TensorFlow للمبتدئ؟
PyTorch — syntax أ simpler، community أكبر في research وLLM، tutorials أكثر. TensorFlow إذا target mobile/production Google-heavy. يمكنك learn both لاحقًا — concepts نفسها.
هل AGI قريب؟
Expert opinions vary wildly. LLMs impressive لكن لا planning، no persistent memory، no true understanding. AGI may be years to decades — or different paradigm needed. Don't hype — focus on useful narrow AI.
كم وقت لأصبح ML Engineer؟
6–18 شهر intensive (Python + math + projects + portfolio) لل motivated self-learner. CS degree faster path. Key: projects on GitHub > certificates alone.
هل DL سيأخذ وظيفتي؟
AI automates tasks — not entire jobs often. Augments knowledge workers. Jobs shift: less data entry، more AI oversight، prompt engineering، AI ethics. Adapt — learn to work with AI.
أين أبدأ مشروعي الأول؟
MNIST (أرقام) — 1 week. CIFAR-10 (صور) — 2 weeks. Kaggle Titanic — tabular ML. Then: fine-tune BERT Arabic for sentiment. Document everything — README، results، lessons learned.