Skip to content

Instantly share code, notes, and snippets.

@Venkatstatistics
Created October 4, 2019 18:04
Show Gist options
  • Save Venkatstatistics/3eb4a2c8f4f76557b5bd4d3d33298c7b to your computer and use it in GitHub Desktop.
Save Venkatstatistics/3eb4a2c8f4f76557b5bd4d3d33298c7b to your computer and use it in GitHub Desktop.
###Spacy Tutorials###
## References: https://course.spacy.io/chapter1 ##
## References: https://spacy.io/usage/spacy-101 ##
### Learning to work with NLP object ###
from spacy.lang.en import English
nlp = English ()
doc = nlp("This is a NLP session")
print (doc.text)
#### Working with SPacy Statistical packages ###
### install basic small package ##
## command to install : python -m spacy download en_core_web_sm ##
import spacy
nlp = spacy.load('en_core_web_sm')
text = input("please enter your text\n")
doc = nlp (text)
for token in doc:
print(token.text, token.lemma_, token.pos_, token.is_stop)
## working with nouns ###
text = input("please enter your text\n")
doc = nlp (text)
for chunk in doc.noun_chunks:
print(chunk)
## demonstrating displacy via named entities ##
text = ("Steve Jobs and Steve Wozniak incorporated Apple Computer on January 3, 1977, in Cupertino, California")
doc = nlp (text)
for ent in doc.ents:
print(ent.text,ent.label_)
from spacy import displacy
displacy.serve(doc, style="ent")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment