0
0
NLPml~10 mins

NER with spaCy in NLP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aen_model
Benglish_core
Cspacy_en
Den_core_web_sm
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect model names like 'english_core' or 'en_model'.
Forgetting to install the model before loading.
2fill in blank
medium

Complete 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'
Anlp
B"Apple is looking at buying a startup"
Ctext
DDoc
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the nlp object itself instead of a string.
Passing a variable name without quotes.
3fill in blank
hard

Fix 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'
Aents
Blabels
Centities
Dtokens
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.
4fill in blank
hard

Fill 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'
Atext
Blabel_
Clabel
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'label' without underscore which returns an integer code.
Using 'string' which is not an attribute.
5fill in blank
hard

Fill 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'
Atext
Blabel_
CORG
Dlabel
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.