استخراج الكيانات باستخدام spaCy
اعرض الكيانات وتسمياتها
استخراج الكيانات باستخدام spaCy درس مجاني في NLP Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في NLP Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة NLP Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
spaCy Does the Work
spaCy ships a trained NER component that finds entities for you. You feed it text and read back labeled spans. 🐍
Load a Model
First load a pipeline that includes NER. The small English model en_core_web_sm is a quick, friendly starting point.
import spacy
nlp = spacy.load("en_core_web_sm")Process Your Text
Pass a string into the pipeline to get a Doc object. The Doc holds tokens, sentences, and the entities spaCy found.
doc = nlp("Sundar Pichai leads Google in California.")The ents Property
Every Doc exposes doc.ents, a tuple of detected entities. Loop over it to inspect each one individually.
for ent in doc.ents:
print(ent)Read the Text
Each entity has a .text attribute holding the exact words matched. This is the raw span lifted from your sentence.
print(ent.text) # e.g. Sundar PichaiRead the Label
Use .label_ (with the trailing underscore) to get a readable label string like PERSON, ORG, or GPE.
print(ent.label_) # e.g. PERSONPutting It Together
One small loop prints both the text and label of every entity, turning a sentence into clean structured data.
for ent in doc.ents:
print(ent.text, ent.label_)Character Positions
Entities also expose start_char and end_char, the offsets in the original string. Handy for highlighting matches later.
print(ent.start_char, ent.end_char)Explain a Label
Forgot what GPE means? Call spacy.explain for a plain-English description of any entity label.
spacy.explain("GPE") # 'Countries, cities, states'Entities Are Spans
Each entity is a Span, a slice of the Doc. So it behaves like a mini-document you can further inspect token by token.
Collect Into a List
A quick comprehension gathers every entity into a list of tuples, ready to save, count, or feed into a report.
results = [(e.text, e.label_) for e in doc.ents]Quick Check
Which attribute gives the readable entity label?
Recap
Load a model, run nlp() on text, then loop doc.ents reading .text and .label_. That is core NER in spaCy. ✅
الأسئلة الشائعة
هل درس «استخراج الكيانات باستخدام spaCy» مجاني؟
نعم — نص درس «استخراج الكيانات باستخدام spaCy» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة NLP Academy، انتقل إلى CoddyKit PRO. تتضمن دورة NLP Academy 4 دروس في المجموع.
ماذا ستتعلم في «استخراج الكيانات باستخدام spaCy»؟
اعرض الكيانات وتسمياتها تتمرن على NLP Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ NLP Academy؟
لا تُشترط خبرة سابقة. NLP Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «استخراج الكيانات باستخدام spaCy»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس NLP Academy هذا؟
نعم. كل درس في NLP Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- ما الذي يُعد كيانًا؟
- استخراج الكيانات باستخدام spaCy
- تصوير الكيانات باستخدام displaCy
- إضافة قواعد مخصّصة للكيانات