Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load the spaCy English model.
NLP
import spacy nlp = spacy.[1]("en_core_web_sm")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tokenize' or 'parse' instead of 'load' to load the model.
✗ Incorrect
The correct function to load a spaCy model is 'load'.
2fill in blank
mediumComplete the code to create a spaCy Doc object from text.
NLP
doc = nlp([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a variable name without defining it.
Passing the nlp object itself.
✗ Incorrect
You need to pass a string of text to the nlp object to create a Doc.
3fill in blank
hardFix the error in the code to print tokens from the Doc object.
NLP
for token in doc: print(token.[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tokens' or 'word' which are not valid token attributes.
✗ Incorrect
The attribute to get the token text is 'text'.
4fill in blank
hardFill both blanks to create a list of token texts for tokens longer than 3 characters.
NLP
tokens = [token.[1] for token in doc if len(token.[2]) > 3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lemma_' or 'pos_' which are not strings for length check.
✗ Incorrect
We use 'token.text' to get the token string and check its length.
5fill in blank
hardFill all three blanks to create a dictionary of token texts and their part-of-speech tags for tokens longer than 4 characters.
NLP
token_pos = {token.[1]: token.[2] for token in doc if len(token.[3]) > 4} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lemma_' instead of 'pos_' for POS tags.
Checking length on 'pos_' which is not a string.
✗ Incorrect
We use 'text' for keys, 'pos_' for values, and 'text' to check length.