[Hindi]NLP 22# Named Entity Recognition P.1 |NLP|Python 3|Natural Language Processing|2019
Code:
# -*- coding: utf-8 -*-
"""NLP_Ex15.ipynb
Automatically generated by Colaboratory.
"""
import spacy
nlp = spacy.load('en_core_web_sm')
def show_ents(doc):
if doc.ents:
for ent in doc.ents:
print(ent.text+' - '+ent.label_+' - '+str(spacy.explain(ent.label_)))
else:
print('No entites found!!!')
doc = nlp(u"Hi, How are you?")
show_ents(doc)
doc = nlp(u"may i go to New York, next May to see Statue of Liberty?")
show_ents(doc)
doc = nlp(u"Can I please have 500 dollars for Microsoft Stocks?")
show_ents(doc)
doc = nlp(u"Tesla to build a U.K. factory for $6 million")
show_ents(doc)
from spacy.tokens import Span
ORG = doc.vocab.strings[u"ORG"]
ORG
new_ent = Span(doc,0,1,label=ORG)
doc.ents = list(doc.ents)+[new_ent]
show_ents(doc)
"""NLP_Ex15.ipynb
Automatically generated by Colaboratory.
"""
import spacy
nlp = spacy.load('en_core_web_sm')
def show_ents(doc):
if doc.ents:
for ent in doc.ents:
print(ent.text+' - '+ent.label_+' - '+str(spacy.explain(ent.label_)))
else:
print('No entites found!!!')
doc = nlp(u"Hi, How are you?")
show_ents(doc)
doc = nlp(u"may i go to New York, next May to see Statue of Liberty?")
show_ents(doc)
doc = nlp(u"Can I please have 500 dollars for Microsoft Stocks?")
show_ents(doc)
doc = nlp(u"Tesla to build a U.K. factory for $6 million")
show_ents(doc)
from spacy.tokens import Span
ORG = doc.vocab.strings[u"ORG"]
ORG
new_ent = Span(doc,0,1,label=ORG)
doc.ents = list(doc.ents)+[new_ent]
show_ents(doc)
0 Comments