Feb 26, 2018

Extract lemmas

Docs
# conda install spacy
# python -m spacy download en

In[1]: import spacy
In[2]: nlp = spacy.load('en')

In[3]: doc = nlp("Hello, my cruel world. I'm leaving you tonight.")

In[4]: list(doc.sents)
Out[4]: [Hello, my cruel world., I'm leaving you tonight.]

In[5]: list(doc)
Out[5]: [Hello,, , my, cruel, world,., I, 'm, leaving, you, tonight, .]

In[6]: doc[8]
Out[6]: leaving
In[7]: doc[8].lemma
Out[7]: 9707179535890930240
In[8]: doc[8].lemma_
Out[8]: 'leave'

In[9]: doc[8].pos_
Out[9]: 'VERB'

In[10]: from spacy import displacy
In[11]: displacy.serve(doc, style='dep')