In [5]:
import spacy
from spacy import displacy

In [6]:
nlp = spacy.load('en')

In [7]:
text1 = "Hi this is my test script. My Name is Rishu and i am learning NLP with Spacy. Hoorah !!!"

In [8]:
doc1 = nlp(text1)

In [22]:
for t in doc1:
    print(t, t.pos_, t.tag_, t.lemma_)


Hi INTJ UH hi
this DET DT this
is AUX VBZ be
my DET PRP$ -PRON-
test NOUN NN test
script NOUN NN script
. PUNCT . .
My DET PRP$ -PRON-
Name NOUN NN name
is AUX VBZ be
Rishu PROPN NNP Rishu
and CCONJ CC and
i PRON PRP i
am AUX VBP be
learning VERB VBG learn
NLP PROPN NNP NLP
with ADP IN with
Spacy PROPN NNP Spacy
. PUNCT . .
Hoorah PROPN NNP Hoorah
! PUNCT . !
! PUNCT . !
! PUNCT . !

In [23]:
displacy.render(doc1, style='dep', jupyter=True, options={'distance': 110})


Hi INTJ this DET is AUX my DET test NOUN script. NOUN My DET Name NOUN is AUX Rishu PROPN and CCONJ i PRON am AUX learning VERB NLP PROPN with ADP Spacy. PROPN Hoorah !!! PROPN intj nsubj poss compound attr poss nsubj attr cc nsubj aux conj dobj prep pobj

In [ ]:
## for handling large texts

doc2 = nlp(u"This is a sentence. This is another, possibly longer sentence.")

# Create spans from Doc.sents:
spans = list(doc2.sents)

displacy.serve(spans, style='dep', options={'distance': 110})


/Users/rishushrivastava/anaconda3/envs/nlpdemo/lib/python3.8/runpy.py:193: UserWarning: [W011] It looks like you're calling displacy.serve from within a Jupyter notebook or a similar environment. This likely means you're already running a local web server, so there's no need to make displaCy start another one. Instead, you should be able to replace displacy.serve with displacy.render to show the visualization.
  return _run_code(code, main_globals, None,
displaCy
This DET is AUX a DET sentence. NOUN nsubj det attr
This DET is AUX another, DET possibly ADV longer ADV sentence. NOUN nsubj attr advmod advmod attr
Using the 'dep' visualizer
Serving on http://0.0.0.0:5000 ...

127.0.0.1 - - [27/May/2020 23:46:26] "GET / HTTP/1.1" 200 8132
127.0.0.1 - - [27/May/2020 23:46:26] "GET /favicon.ico HTTP/1.1" 200 8132

In [ ]: