Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the spaCy library for dependency parsing.
NLP
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing nltk instead of spaCy
Using sklearn which is for machine learning, not NLP
✗ Incorrect
spaCy is a popular library for natural language processing, including dependency parsing.
2fill in blank
mediumComplete the code to load the English language model in spaCy.
NLP
nlp = spacy.load('[1]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a French or German model for English text
Misspelling the model name
✗ Incorrect
The English small model in spaCy is named 'en_core_web_sm'.
3fill in blank
hardFix the error in the code to get the dependency label of the first token.
NLP
doc = nlp('I love AI') label = doc[0].[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pos_ instead of dep_
Using text which gives the token string, not the dependency label
✗ Incorrect
The dependency label of a token is accessed with the dep_ attribute in spaCy.
4fill in blank
hardFill both blanks to create a dictionary of tokens and their dependency labels.
NLP
dep_dict = {token.[1]: token.[2] for token in doc} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pos_ instead of dep_ for dependency labels
Using lemma_ instead of text for token keys
✗ Incorrect
We use text for the token string and dep_ for its dependency label.
5fill in blank
hardFill all three blanks to print each token, its head token, and the dependency relation.
NLP
for token in doc: print(f"Token: {token.[1], Head: {token.[2].[3]")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dep_ instead of text for printing token strings
Trying to print head without accessing its text attribute
✗ Incorrect
We print the token's text, the head token object, and the head token's text.