0
0
ML Pythonml~10 mins

Named Entity Recognition basics in ML Python - Interactive Code Practice

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

Complete 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'
Aner_model
Ben_core_web_sm
Ctext_classifier
Dtokenizer
Attempts:
3 left
💡 Hint
Common Mistakes
Using a model name that does not exist in spaCy.
Confusing NER model with tokenizer or text classifier.
2fill in blank
medium

Complete 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'
Acategory
Btype
Ctag
Dlabel_
Attempts:
3 left
💡 Hint
Common Mistakes
Using ent.type which does not exist.
Using ent.tag which is for part-of-speech tags.
3fill in blank
hard

Fix 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'
Aentity
Blabel
Clabel_
Dtext
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.
4fill in blank
hard

Fill 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'
Atext
Blabel_
Cstart_char
Dend_char
Attempts:
3 left
💡 Hint
Common Mistakes
Using character offsets instead of text or label.
Mixing up keys and values.
5fill in blank
hard

Fill 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'
Atext
Blabel_
CPERSON
Dent
Attempts:
3 left
💡 Hint
Common Mistakes
Using ent.label instead of ent.label_.
Comparing label to lowercase 'person' instead of uppercase 'PERSON'.