Skip to the content.

Code Snippets For SpaCy

Code Snippets For SpaCy

%load_ext autoreload
%autoreload 2
import spacy
# Run this line if you haven just installed spacy
# !python -m spacy download en_core_web_sm
import en_core_web_sm
nlp = en_core_web_sm.load()
doc = nlp(
"Trump has long touted China’s huge exports to the U.S. "
"as a sign that Beijing has been taking advantage "
"of American businesses for decades."
)

Named Entity Recognition

Upon loading a corpus, SpaCy has actively run functions like POS Tags and NER if a language model provides.

doc.ents

show the NE labels

[(ent, ent.label_) for ent in doc.ents]

POS Tag

list(doc.noun_chunks)