تقسيم النص لنماذج Transformer
الكلمات الجزئية والحشو وأقنعة الانتباه
تقسيم النص لنماذج Transformer درس مجاني في NLP Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في NLP Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة NLP Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Tokens Come First
Before a transformer can learn anything, your text must become numbers. That conversion job belongs to the tokenizer.
Match the Model
Always load the tokenizer that was trained with your model. A mismatched vocabulary produces garbage ids the model never saw.
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("bert-base-uncased")Subword Pieces
Modern tokenizers split rare words into smaller chunks called subwords, so even unknown text stays representable.
print(tok.tokenize("tokenization"))Why Subwords Win
Subwords keep the vocabulary small while still handling typos and new words. The model rarely meets a true unknown token.
From Tokens to Ids
Each subword maps to an integer id. Calling the tokenizer on text returns those ids ready for the model.
enc = tok("Fine-tuning is fun")
print(enc["input_ids"])Special Tokens
Tokenizers add markers like CLS and SEP so the model knows where a sequence starts and ends. These are the special tokens.
Padding to Equal Length
Batches need same-length rows, so shorter texts get filler tokens. This step is called padding.
tok(texts, padding=True)Truncation for Long Text
Models cap input length, so very long text is cut to fit. Enabling truncation keeps every example within the limit.
tok(texts, truncation=True, max_length=128)The Attention Mask
An attention mask marks real tokens as 1 and padding as 0, so the model ignores the filler positions.
print(enc["attention_mask"])Return Tensors
Ask the tokenizer for framework tensors directly so the output drops straight into training without extra conversion.
tok("hello", return_tensors="pt")Decode Back to Text
To read predictions, run ids through decode and the tokenizer rebuilds the original text, special tokens stripped.
print(tok.decode(enc["input_ids"]))Quick Check
What is the job of the attention mask during batching?
Recap
Tokenizers turn text into subword ids, add special tokens, then handle padding, truncation, and the attention mask for clean batches. ✅
الأسئلة الشائعة
هل درس «تقسيم النص لنماذج Transformer» مجاني؟
نعم — نص درس «تقسيم النص لنماذج Transformer» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة NLP Academy، انتقل إلى CoddyKit PRO. تتضمن دورة NLP Academy 4 دروس في المجموع.
ماذا ستتعلم في «تقسيم النص لنماذج Transformer»؟
الكلمات الجزئية والحشو وأقنعة الانتباه تتمرن على NLP Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ NLP Academy؟
لا تُشترط خبرة سابقة. NLP Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «تقسيم النص لنماذج Transformer»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس NLP Academy هذا؟
نعم. كل درس في NLP Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- جولة في مكتبة Transformers
- تقسيم النص لنماذج Transformer
- الضبط الدقيق باستخدام Trainer API
- تقييم النموذج وحفظه