Question: Explain this named entity code Code: #accessing entity annotation import spacy nlp = spacy.load(en_core_web_sm) doc = nlp(The Eiffel Tower is located in Paris, France) #
Explain this named entity code
Code:
#accessing entity annotation
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("The Eiffel Tower is located in Paris, France")
# document level
ents = [(e.text, e.start_char, e.end_char, e.label_) for e in doc.ents]
print(ents)
# token level
ent_paris = [doc[0].text, doc[0].ent_iob_, doc[0].ent_type_]
ent_france = [doc[1].text, doc[1].ent_iob_, doc[1].ent_type_]
print(ent_paris) # ['San', 'B', 'GPE']
print(ent_france) # ['Francisco', 'I', 'GPE']
Output:
[('The Eiffel Tower', 0, 16, 'ORG'), ('Paris', 31, 36, 'GPE'), ('France', 38, 44, 'GPE')]
['The', 'B', 'ORG']
['Eiffel', 'I', 'ORG']
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
