spaCy ile Natural Language Processing
Azadeh Mobasher
Principal Data Scientist
| POS | Açıklama | Örnek |
|---|---|---|
| VERB | Fiil | run, eat, ate, take |
| NOUN | İsim | man, airplane, tree, flower |
| ADJ | Sıfat | big, old, incompatible, conflicting |
| ADV | Zarf | very, down, there, tomorrow |
| CONJ | Bağlaç | and, or, but |
spaCy, POS etiketlerini nlp işlem hattındaki pos_ özelliğinde tutarspacy.explain() bir POS etiketini açıklarverb_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')]
| Varlık türü | Açıklama |
|---|---|
| PERSON | Adı bilinen kişi veya aile |
| ORG | Şirketler, kurumlar vb. |
| GPE | Coğrafi-siyasi varlık; ülkeler, şehirler vb. |
| LOC | GPE olmayan yerler; dağ sıraları vb. |
| DATE | Mutlak/göreli tarihler veya dönemler |
| TIME | Bir günden küçük zaman dilimleri |
spaCy modelleri adlandırılmış varlıkları NER işlem hattı bileşeniyle çıkarırdoc.ents özelliğiyle erişilirspaCy her varlığı etiket (.label_) ile işaretler
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 kapsayıcısındaki her token’ın varlık türüne de erişebiliriz
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, modern bir görselleştirici olan displaCy ile gelirdisplaCy varlık görselleştirici, adlandırılmış varlıkları ve etiketlerini vurgularimport 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 ile Natural Language Processing