0Pricing
NLP Academy · درس

إنشاء كاشف للبريد المزعج

درّبه على رسائل معنونة

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

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

Your First Real Model

Time to build something useful: a spam filter. You will train a classifier on labeled messages and let it judge brand-new ones.

Start With Labeled Data

Every supervised model needs examples with answers. Here each message comes with a label of spam or ham, the friendly name for not-spam.

messages = ["win cash now", "lunch at noon?", "free prize click"]
labels = ["spam", "ham", "spam"]
print(len(messages), len(labels))

Turn Text Into Numbers

The model cannot read raw words, so you count them first. A CountVectorizer converts each message into a row of word counts.

from sklearn.feature_extraction.text import CountVectorizer
vec = CountVectorizer()
X = vec.fit_transform(messages)

Meet MultinomialNB

For word counts, the right tool is MultinomialNB, the count-based flavor of Naive Bayes built right into scikit-learn.

from sklearn.naive_bayes import MultinomialNB
model = MultinomialNB()

Fit the Model

Training is one line: hand the model your features and labels. The fit call counts words per class and stores the probabilities.

model.fit(X, labels)
print("trained on", X.shape[0], "messages")

Predict New Mail

To judge a fresh message, vectorize it the same way and call predict. The model returns its best guess for spam or ham.

new = vec.transform(["free cash prize"])
print(model.predict(new))

Reuse the Vectorizer

New text must use the same vocabulary the model learned. Always call transform, never fit again, or the columns will not line up.

Peek at the Confidence

Beyond the label, the model can report how sure it is. The predict_proba method gives a probability for each possible class.

print(model.predict_proba(new))

Hold Out a Test Set

Never grade a model on the data it trained on. Split off a test set so you can measure how it does on unseen messages.

Score the Filter

Run predictions on the held-out messages and compare to the truth. That accuracy tells you whether your spam filter actually works. 📬

Iterate to Improve

More clean data and better preprocessing lift results fast. Treat this filter as a baseline you can steadily refine, not a finished product.

Quick Check

How should you prepare a new message before predicting on it?

Recap

You vectorized messages, trained MultinomialNB, and predicted spam on new text. Reusing the fitted vectorizer keeps your features aligned. ✅

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

هل درس «إنشاء كاشف للبريد المزعج» مجاني؟

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

ماذا ستتعلم في «إنشاء كاشف للبريد المزعج»؟

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

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

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

كم من الوقت يستغرق درس «إنشاء كاشف للبريد المزعج»؟

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

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

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

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

  1. الحدس وراء Naive Bayes
  2. إنشاء كاشف للبريد المزعج
  3. نماذج Multinomial وBernoulli
  4. قراءة تنبؤات النموذج
← العودة إلى NLP Academy