Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load the English model in spaCy.
NLP
import spacy nlp = spacy.load('[1]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect model names like 'english_core' or 'en_model'.
Forgetting to install the model before loading.
✗ Incorrect
The correct model name to load the small English model in spaCy is 'en_core_web_sm'.
2fill in blank
mediumComplete the code to process the text and create a spaCy Doc object.
NLP
doc = nlp('[1]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the nlp object itself instead of a string.
Passing a variable name without quotes.
✗ Incorrect
To create a Doc object, you pass the text string to the nlp model, e.g., nlp("Apple is looking at buying a startup").
3fill in blank
hardFix the error in the code to print named entities and their labels.
NLP
for ent in doc.[1]: print(ent.text, ent.label_)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tokens' or 'labels' which are not attributes of Doc for entities.
Using 'entities' which is not a valid attribute.
✗ Incorrect
The correct attribute to access named entities in a Doc object is 'ents'.
4fill in blank
hardFill both blanks to create a dictionary of entity texts and their labels.
NLP
entities = {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 'label' without underscore which returns an integer code.
Using 'string' which is not an attribute.
✗ Incorrect
Each entity has a 'text' attribute for the entity string and 'label_' attribute for the label name.
5fill in blank
hardFill all three blanks to filter entities with label 'ORG' and create a list of their texts.
NLP
org_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 'label' instead of 'label_' which gives numeric codes.
Comparing label to 'org' in lowercase which is case sensitive.
✗ Incorrect
To get texts of entities labeled 'ORG', use ent.text and check ent.label_ == 'ORG'.