Complete the code to load a pre-trained entity linking model from spaCy.
import spacy nlp = spacy.load('[1]')
The correct model for entity linking in spaCy is en_core_entity_linker, which includes the entity linking pipeline component.
Complete the code to extract entities and their linked Wikipedia IDs from a processed document.
for ent in doc.ents: print(ent.text, ent.kb_id_[1])
The attribute kb_id_ is accessed with a trailing underscore and no parentheses or brackets because it is a string property of the entity span.
Fix the error in the code to add the entity linker component to the spaCy pipeline.
nlp = spacy.load('en_core_web_sm') nlp.add_pipe('[1]', last=True)
The entity linker component is named entity_linker and must be added explicitly to the pipeline if not included by default.
Fill both blanks to create a dictionary of entity texts mapped to their Wikipedia URLs.
entity_links = {ent.text: 'https://en.wikipedia.org/wiki/' + ent.kb_id_[1] for ent in doc.ents if ent.kb_id_[2] != ''}The kb_id_ attribute is accessed as a string property with a trailing underscore and no parentheses or brackets.
Fill all three blanks to filter entities with confidence score above 0.85 and create a dictionary of their texts and Wikipedia URLs.
entity_links = {ent.text: 'https://en.wikipedia.org/wiki/' + ent.kb_id_[1] for ent in doc.ents if ent.kb_id_[2] != '' and ent._.kb_[3] > 0.85}Access kb_id_ as a property with underscore, and the confidence score is stored in the custom extension attribute kb_score accessed as ent._.kb_score.