Procesarea limbajului natural cu spaCy
Azadeh Mobasher
Principal Data Scientist
| POS | Descriere | Exemplu |
|---|---|---|
| VERB | Verb | run, eat, ate, take |
| NOUN | Substantiv | man, airplane, tree, flower |
| ADJ | Adjectiv | big, old, incompatible, conflicting |
| ADV | Adverb | very, down, there, tomorrow |
| CONJ | Conjuncție | and, or, but |
spaCy stochează etichetele POS în caracteristica pos_ a pipeline-ului nlpspacy.explain() explică o etichetă POS dată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')]
| Tip entitate | Descriere |
|---|---|
| PERSON | Persoană sau familie |
| ORG | Companii, instituții etc. |
| GPE | Entitate geopolitică: țări, orașe etc. |
| LOC | Locații non-GPE, lanțuri muntoase etc. |
| DATE | Date sau perioade absolute ori relative |
| TIME | Interval de timp mai mic de o zi |
spaCy extrag entități denumite prin componenta de pipeline NERdoc.entsspaCy etichetează fiecare entitate cu un tip (.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
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 include un vizualizator modern: displaCydisplaCy evidențiază entitățile denumite și etichetele lorimport 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")
Procesarea limbajului natural cu spaCy