تدريب مصنّف LSTM
درّب نموذجًا ذي بوابات على تسلسلات
تدريب مصنّف LSTM درس مجاني في NLP Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في NLP Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة NLP Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
From Theory to Practice
Time to build something. You will wire an LSTM classifier that reads a sequence of words and predicts a single label. 🛠️
Text Becomes Integers
First each word maps to an integer id, so a sentence turns into a list of numbers your model can tokenize and process.
ids = [vocab[w] for w in tokens]Pad to Equal Length
LSTMs need uniform batches, so you pad short sequences with zeros and truncate long ones to a fixed length.
X = pad_sequences(ids, maxlen=200)The Embedding Layer
An embedding layer turns each integer id into a dense learnable vector, giving the LSTM rich word meaning instead of raw numbers.
Embedding(input_dim=10000, output_dim=128)Add the LSTM Layer
Next comes the LSTM layer. It reads the embedded sequence step by step and outputs a summary of the whole text.
model.add(LSTM(64))The Output Layer
A final dense layer with sigmoid maps the LSTM summary to a probability, perfect for binary classification like positive or negative.
model.add(Dense(1, activation='sigmoid'))Compile the Model
You compile with a loss and optimizer. Binary cross-entropy and Adam are a reliable starting pair for two-class text.
model.compile(loss='binary_crossentropy', optimizer='adam')Fit on Your Data
Calling fit runs training: the model reads batches, compares predictions to labels, and adjusts its weights to reduce loss.
model.fit(X_train, y_train, epochs=3, batch_size=32)Watch for Overfitting
If training accuracy climbs but validation drops, you are overfitting. Add dropout or stop training earlier to fix it.
model.add(LSTM(64, dropout=0.2))Evaluate and Predict
After training, score the model on held-out data with evaluate, then call predict to label brand-new text.
model.evaluate(X_test, y_test)The Whole Pipeline
So the full pipeline is tokenize, pad, embed, run the LSTM, then classify. Each piece feeds cleanly into the next.
Quick Check
Recall the model layout you just built.
Recap
You built an LSTM classifier: tokenize, pad, embed, run the LSTM, and output a label. Add dropout to guard against overfitting. ✅
الأسئلة الشائعة
هل درس «تدريب مصنّف LSTM» مجاني؟
نعم — نص درس «تدريب مصنّف LSTM» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة NLP Academy، انتقل إلى CoddyKit PRO. تتضمن دورة NLP Academy 4 دروس في المجموع.
ماذا ستتعلم في «تدريب مصنّف LSTM»؟
درّب نموذجًا ذي بوابات على تسلسلات تتمرن على NLP Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ NLP Academy؟
لا تُشترط خبرة سابقة. NLP Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «تدريب مصنّف LSTM»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس NLP Academy هذا؟
نعم. كل درس في NLP Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.