खाली spaCy मॉडल के साथ EntityRuler
EntityRuler आपको doc.ents में entities जोड़ने देता है. इसे सटीकता बढ़ाने के लिए EntityRecognizer (named-entity recognition के लिए spaCy पाइपलाइन कंपोनेंट) के साथ संयोजित किया जा सकता है, या अकेले एक पूरी तरह rule-based entity recognition सिस्टम लागू करने के लिए उपयोग किया जा सकता है. इस अभ्यास में, आप एक खाली spaCy English मॉडल में EntityRuler कंपोनेंट जोड़ने का अभ्यास करेंगे और दिए गए text की named entities को पूरी तरह rule-based named-entity recognition से वर्गीकृत करेंगे.
spaCy पैकेज पहले से इम्पोर्ट किया गया है और एक खाली spaCy English मॉडल nlp के रूप में आपके उपयोग के लिए तैयार है. लोअर केस किए हुए OpenAI और Microsoft को ORG के रूप में वर्गीकृत करने के लिए patterns की एक सूची आपके लिए पहले से बनाई गई है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
spaCy के साथ Natural Language Processing
अभ्यास निर्देश
- पाइपलाइन में एक
EntityRulerकंपोनेंट बनाएँ और जोड़ें. - दिए गए patterns को
EntityRulerकंपोनेंट में जोड़ें. - दिए गए
textपर मॉडल चलाएँ और उसका संबंधितDocकंटेनर बनाएँ. Docकंटेनर में मौजूद सभी entities के लिए (entity का text और प्रकार) का ट्यूपल प्रिंट करें
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
nlp = spacy.blank("en")
patterns = [{"label": "ORG", "pattern": [{"LOWER": "openai"}]},
{"label": "ORG", "pattern": [{"LOWER": "microsoft"}]}]
text = "OpenAI has joined forces with Microsoft."
# Add EntityRuler component to the model
entity_ruler = nlp.____("entity_ruler")
# Add given patterns to the EntityRuler component
entity_ruler.____(____)
# Run the model on a given text
doc = nlp(____)
# Print entities text and type for all entities in the Doc container
print([(ent.____, ent.____) for ent in doc.____])