spaCy EntityRuler

spaCy के साथ Natural Language Processing

Azadeh Mobasher

Principal Data Scientist

spaCy EntityRuler

 

  • EntityRuler एक Doc कंटेनर में named-entities जोड़ता है
  • इसे अकेले या EntityRecognizer के साथ इस्तेमाल किया जा सकता है
  • सटीक स्ट्रिंग मैच के लिए phrase entity patterns (string):
{"label": "ORG", "pattern": "Microsoft"}
  • Token entity patterns जहाँ एक dictionary एक token का वर्णन करती है (list):
{"label": "GPE", "pattern": [{"LOWER": "san"}, {"LOWER": "francisco"}]}
spaCy के साथ Natural Language Processing

spaCy पाइपलाइन में EntityRuler जोड़ना

 

  • .add_pipe() मेथड का उपयोग
  • patterns की लिस्ट .add_patterns() मेथड से जोड़ें

 

nlp = spacy.blank("en")
entity_ruler = nlp.add_pipe("entity_ruler")
patterns = [{"label": "ORG", "pattern": "Microsoft"},
            {"label": "GPE", "pattern": [{"LOWER": "san"}, {"LOWER": "francisco"}]}]
entity_ruler.add_patterns(patterns)
spaCy के साथ Natural Language Processing

spaCy पाइपलाइन में EntityRuler जोड़ना

 

  • .ents में EntityLinker कॉम्पोनेंट के नतीजे स्टोर होते हैं

 

doc = nlp("Microsoft is hiring software developer in San Francisco.")
print([(ent.text, ent.label_) for ent in doc.ents])
[('Microsoft', 'ORG'), ('San Francisco', 'GPE')]
spaCy के साथ Natural Language Processing

EntityRuler काम में

 

  • spaCy पाइपलाइन कॉम्पोनेंट्स के साथ इंटीग्रेट होता है
  • named-entity recognizer को बेहतर बनाता है

  • EntityRuler के बिना spaCy मॉडल:

nlp = spacy.load("en_core_web_sm")

doc = nlp("Manhattan associates is a company in the U.S.")
print([(ent.text, ent.label_) for ent in doc.ents])
>>> [('Manhattan', 'GPE'), ('U.S.', 'GPE')]
spaCy के साथ Natural Language Processing

EntityRuler काम में

 

  • मौजूदा ner कॉम्पोनेंट के बाद EntityRuler जोड़ा:
nlp = spacy.load("en_core_web_sm")
ruler = nlp.add_pipe("entity_ruler", after='ner')
patterns = [{"label": "ORG", "pattern": [{"lower": "manhattan"}, {"lower": "associates"}]}]
ruler.add_patterns(patterns)

doc = nlp("Manhattan associates is a company in the U.S.")
print([(ent.text, ent.label_) for ent in doc.ents])
>>> [('Manhattan', 'GPE'), ('U.S.', 'GPE')]
spaCy के साथ Natural Language Processing

EntityRuler काम में

 

  • मौजूदा ner कॉम्पोनेंट से पहले EntityRuler जोड़ा:
nlp = spacy.load("en_core_web_sm")
ruler = nlp.add_pipe("entity_ruler", before='ner')
patterns = [{"label": "ORG", "pattern": [{"lower": "manhattan"}, {"lower": "associates"}]}]
ruler.add_patterns(patterns)

doc = nlp("Manhattan associates is a company in the U.S.")
print([(ent.text, ent.label_) for ent in doc.ents])
>>> [('Manhattan associates', 'ORG'), ('U.S.', 'GPE')]
spaCy के साथ Natural Language Processing

अभ्यास करते हैं!

spaCy के साथ Natural Language Processing

Preparing Video For Download...