spaCy के साथ Natural Language Processing
Azadeh Mobasher
Principal Data Scientist
| POS | विवरण | उदाहरण |
|---|---|---|
| VERB | क्रिया | run, eat, ate, take |
| NOUN | संज्ञा | man, airplane, tree, flower |
| ADJ | विशेषण | big, old, incompatible, conflicting |
| ADV | क्रिया-विशेषण | very, down, there, tomorrow |
| CONJ | संयोजक | and, or, but |
spaCy nlp पाइपलाइन के pos_ फीचर में POS टैग कैप्चर करता हैspacy.explain() दिए गए POS टैग की व्याख्या करता हैverb_sent = "I watch TV."print([(token.text, token.pos_, spacy.explain(token.pos_)) for token in nlp(verb_sent)])
[('I', 'PRON', 'pronoun'),
('watch', 'VERB', 'verb'),
('TV', 'NOUN', 'noun'),
('.', 'PUNCT', 'punctuation')]
noun_sent = "I left without my watch."print([(token.text, token.pos_, spacy.explain(token.pos_)) for token in nlp(noun_sent)])
[('I', 'PRON', 'pronoun'),
('left', 'VERB', 'verb'),
('without', 'ADP', 'adposition'),
('my', 'PRON', 'pronoun'),
('watch', 'NOUN', 'noun'),
('.', 'PUNCT', 'punctuation')]
| Entity type | विवरण |
|---|---|
| PERSON | नामित व्यक्ति या परिवार |
| ORG | कंपनियाँ, संस्थान आदि |
| GPE | भू-राजनीतिक इकाई, देश, शहर आदि |
| LOC | गैर-GPE स्थान, पर्वतमाला आदि |
| DATE | पूर्ण/सापेक्ष तिथियाँ या अवधि |
| TIME | एक दिन से छोटी समय-एकाई |
spaCy मॉडल NER पाइपलाइन कॉम्पोनेंट से named entities निकालते हैंdoc.ents प्रॉपर्टी से मिलती हैंspaCy हर entity को उसके लेबल (.label_) से भी टैग करता है
import spacy nlp = spacy.load("en_core_web_sm") text = "Albert Einstein was genius." doc = nlp(text)print([(ent.text, ent.start_char, ent.end_char, ent.label_) for ent in doc.ents])
>>> [('Albert Einstein', 0, 15, 'PERSON')]
Doc कंटेनर में हर टोकन के entity प्रकार भी देख सकते हैं
import spacy nlp = spacy.load("en_core_web_sm") text = "Albert Einstein was genius." doc = nlp(text)print([(token.text, token.ent_type_) for token in doc])
>>> [('Albert', 'PERSON'), ('Einstein', 'PERSON'),
('was', ''), ('genius', ''), ('.', '')]
spaCy में एक आधुनिक विजुअलाइज़र है: displaCydisplaCy entity विजुअलाइज़र named entities और उनके लेबल हाईलाइट करता हैimport spacy from spacy import displacy text = "Albert Einstein was genius." nlp = spacy.load("en_core_web_sm") doc = nlp(text)displacy.serve(doc, style="ent")
spaCy के साथ Natural Language Processing