Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the NER model from spaCy.
ML Python
import spacy nlp = spacy.load('[1]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a model name that does not exist in spaCy.
Confusing NER model with tokenizer or text classifier.
✗ Incorrect
The correct spaCy model for basic English NER is en_core_web_sm.
2fill in blank
mediumComplete the code to extract named entities from the text.
ML Python
doc = nlp(text) entities = [(ent.text, ent.[1]) for ent in doc.ents]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
ent.type which does not exist.Using
ent.tag which is for part-of-speech tags.✗ Incorrect
In spaCy, the entity label is accessed with ent.label_.
3fill in blank
hardFix the error in the code to correctly print entity text and label.
ML Python
for ent in doc.ents: print(ent.text, ent.[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
ent.label which returns an integer code, not the string.Trying to print
ent.entity which does not exist.✗ Incorrect
The correct attribute to get the entity label as a string is label_, not label.
4fill in blank
hardFill both blanks to create a dictionary of entity texts and their labels.
ML Python
entity_dict = {ent.[1]: ent.[2] for ent in doc.ents} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using character offsets instead of text or label.
Mixing up keys and values.
✗ Incorrect
Use ent.text as the key and ent.label_ as the value to map entity text to its label.
5fill in blank
hardFill all three blanks to filter entities with label 'PERSON' and get their texts.
ML Python
person_entities = [ent.[1] for ent in doc.ents if ent.[2] == '[3]']
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
ent.label instead of ent.label_.Comparing label to lowercase 'person' instead of uppercase 'PERSON'.
✗ Incorrect
We want the text of entities where the label is 'PERSON'. So use ent.text, check ent.label_, and compare to 'PERSON'.