0Pricing
Deep Learning Academy · درس

الإيقاف المبكر عند خسارة التحقق

توقّف قبل حدوث فرط التكيّف

الإيقاف المبكر عند خسارة التحقق درس مجاني في Deep Learning Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Deep Learning Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Training Too Long Hurts

More epochs are not always better. Past a point the model starts memorizing noise, and validation results get worse. Early stopping ends training at the sweet spot.

Watch Validation Loss

The signal you track is validation loss. While it keeps falling the model is still generalizing better, so you let training continue.

The Turning Point

Eventually training loss keeps dropping but validation loss bottoms out and rises. That upward turn is the moment overfitting takes over.

Remember the Best Score

Keep a variable for the best validation loss seen so far. Each epoch you compare the new score against it to decide if progress was made.

best_loss = float('inf')

Count Epochs Without Gain

When an epoch fails to beat the best, increase a counter. A reset to zero happens the moment validation loss improves again.

if val_loss < best_loss:
    best_loss = val_loss
    counter = 0
else:
    counter += 1

Set a Patience

Patience is how many bad epochs you tolerate before quitting. A small value stops fast; a larger one rides out noisy dips.

patience = 5

Break When Patience Runs Out

Once the counter reaches patience, stop the loop. This break ends training before the model wastes time getting worse.

if counter >= patience:
    break

Save the Best Along the Way

Each time validation improves, write a checkpoint. When you finally stop, that saved file holds the strongest model, not the last one.

if val_loss < best_loss:
    torch.save(model.state_dict(), 'best.pt')

Add a Min Delta

Tiny wobbles can look like fake progress. A min_delta requires improvement bigger than a threshold before resetting the patience counter.

if val_loss < best_loss - min_delta:
    best_loss = val_loss

Restore the Best at the End

After the loop, load your saved checkpoint so you actually deploy the best model. Stopping early is pointless if you keep the worse final weights.

model.load_state_dict(torch.load('best.pt'))

A Free Form of Regularization

Early stopping costs nothing extra yet fights overfitting like a regularizer. It pairs nicely with dropout and weight decay for even steadier training.

Quick Check

What does the patience setting control in early stopping?

Recap

Track validation loss, count epochs without gain, stop once patience runs out, and restore the best checkpoint. Early stopping saves time and curbs overfitting. ⏹️

الأسئلة الشائعة

هل درس «الإيقاف المبكر عند خسارة التحقق» مجاني؟

نعم — نص درس «الإيقاف المبكر عند خسارة التحقق» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Deep Learning Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.

ماذا ستتعلم في «الإيقاف المبكر عند خسارة التحقق»؟

توقّف قبل حدوث فرط التكيّف تتمرن على Deep Learning Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Deep Learning Academy؟

لا تُشترط خبرة سابقة. Deep Learning Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «الإيقاف المبكر عند خسارة التحقق»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Deep Learning Academy هذا؟

نعم. كل درس في Deep Learning Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. تقسيم بيانات التدريب والتحقق والاختبار
  2. حلقة Epoch مع التحقق
  3. الحفظ والتحميل باستخدام state_dict
  4. الإيقاف المبكر عند خسارة التحقق
← العودة إلى Deep Learning Academy