Bird
Raised Fist0
NLPml~20 mins

Dependency parsing in NLP - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Dependency Parsing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Dependency Parsing Output

Given the sentence: "The cat sat on the mat." and its dependency parse, which of the following correctly represents the head of the word "sat"?

A"sat" is the root of the sentence, so it has no head.
B"sat" has the head "cat" because the cat is doing the action.
C"sat" has the head "on" because it shows location.
D"sat" has the head "mat" because it is the object.
Attempts:
2 left
💡 Hint

Think about which word is the main verb that connects the sentence.

Predict Output
intermediate
2:00remaining
Output of Dependency Parsing with spaCy

What is the output of the following code snippet that uses spaCy to parse the sentence "She enjoys reading books." and prints each token's text and its dependency label?

NLP
import spacy
nlp = spacy.load('en_core_web_sm')
doc = nlp('She enjoys reading books.')
output = [(token.text, token.dep_) for token in doc]
print(output)
A[('She', 'nsubj'), ('enjoys', 'ROOT'), ('reading', 'xcomp'), ('books', 'dobj'), ('.', 'punct')]
B[('She', 'dobj'), ('enjoys', 'nsubj'), ('reading', 'ROOT'), ('books', 'xcomp'), ('.', 'punct')]
C[('She', 'ROOT'), ('enjoys', 'nsubj'), ('reading', 'dobj'), ('books', 'xcomp'), ('.', 'punct')]
D[('She', 'punct'), ('enjoys', 'dobj'), ('reading', 'nsubj'), ('books', 'ROOT'), ('.', 'xcomp')]
Attempts:
2 left
💡 Hint

Remember the subject usually has the label nsubj and the main verb is ROOT.

Model Choice
advanced
2:30remaining
Choosing a Dependency Parsing Model for Low-Resource Language

You want to build a dependency parser for a low-resource language with very limited annotated data. Which model approach is most suitable?

ATrain a large transformer-based parser from scratch on the small dataset.
BUse a rule-based parser handcrafted for the language without machine learning.
CUse a pre-trained multilingual model and fine-tune it on the small dataset.
DTrain a simple linear classifier on raw text without any linguistic features.
Attempts:
2 left
💡 Hint

Think about leveraging existing knowledge from other languages.

Metrics
advanced
1:30remaining
Evaluating Dependency Parsing Accuracy

Which metric best measures how well a dependency parser predicts the correct head for each word in a sentence?

ABLEU score
BPerplexity
CF1 score for named entity recognition
DUnlabeled Attachment Score (UAS)
Attempts:
2 left
💡 Hint

Focus on metrics that evaluate syntactic structure correctness.

🔧 Debug
expert
3:00remaining
Debugging Incorrect Dependency Parse Output

You trained a dependency parser, but it often predicts the root word incorrectly, assigning root to punctuation marks. Which is the most likely cause?

AThe evaluation metric is not suitable for dependency parsing.
BThe training data has incorrect root annotations for punctuation.
CThe tokenizer splits words incorrectly causing misalignment.
DThe model uses a too high learning rate causing overfitting.
Attempts:
2 left
💡 Hint

Check the quality of your training annotations carefully.

Practice

(1/5)
1. What is the main purpose of dependency parsing in Natural Language Processing?
easy
A. To show how words in a sentence are connected
B. To translate sentences into another language
C. To count the number of words in a sentence
D. To generate new sentences automatically

Solution

  1. Step 1: Understand dependency parsing

    Dependency parsing analyzes sentence structure by showing relationships between words.
  2. Step 2: Compare options

    Only To show how words in a sentence are connected correctly describes this purpose; others describe different NLP tasks.
  3. Final Answer:

    To show how words in a sentence are connected -> Option A
  4. Quick Check:

    Dependency parsing = word connections [OK]
Hint: Dependency parsing = word connection map [OK]
Common Mistakes:
  • Confusing parsing with translation
  • Thinking it counts words only
  • Mixing with sentence generation
2. Which of the following is the correct way to access the dependency label of a token using spaCy in Python?
doc = nlp('I love cats')
easy
A. doc[1].dep_
B. doc.dep_[1]
C. doc[1].dependency
D. doc.dep[1]

Solution

  1. Step 1: Recall spaCy token attributes

    In spaCy, each token has a dep_ attribute accessed by doc[index].dep_.
  2. Step 2: Check options for correct syntax

    Only doc[1].dep_ uses correct attribute and indexing syntax.
  3. Final Answer:

    doc[1].dep_ -> Option A
  4. Quick Check:

    Token dependency label = doc[index].dep_ [OK]
Hint: Use token.dep_ to get dependency label [OK]
Common Mistakes:
  • Using wrong attribute name like dep or dependency
  • Trying to index dep_ attribute
  • Confusing token and doc object
3. Given the code below, what will be the output?
import spacy
nlp = spacy.load('en_core_web_sm')
doc = nlp('She eats an apple')
for token in doc:
    print(f'{token.text} -> {token.dep_}')
medium
A. She -> det eats -> dobj an -> nsubj apple -> ROOT
B. She -> dobj eats -> nsubj an -> ROOT apple -> det
C. She -> ROOT eats -> nsubj an -> dobj apple -> det
D. She -> nsubj eats -> ROOT an -> det apple -> dobj

Solution

  1. Step 1: Understand dependency roles in sentence

    In 'She eats an apple', 'eats' is the main verb (ROOT), 'She' is subject (nsubj), 'an' is determiner (det), 'apple' is direct object (dobj).
  2. Step 2: Match roles to output

    She -> nsubj eats -> ROOT an -> det apple -> dobj correctly matches each word to its dependency label.
  3. Final Answer:

    She -> nsubj eats -> ROOT an -> det apple -> dobj -> Option D
  4. Quick Check:

    Subject = nsubj, Verb = ROOT, Object = dobj [OK]
Hint: Main verb is ROOT; subject is nsubj; object is dobj [OK]
Common Mistakes:
  • Mixing subject and object labels
  • Confusing determiner with object
  • Assuming first word is ROOT
4. Identify the error in this spaCy dependency parsing code:
import spacy
nlp = spacy.load('en_core_web_sm')
doc = nlp('Dogs bark loudly')
for token in doc:
    print(token.dep)
medium
A. Incorrect model name in spacy.load
B. doc should be a list, not a spaCy Doc object
C. Missing underscore in token.dep_ attribute
D. print statement syntax is wrong

Solution

  1. Step 1: Check token attribute usage

    spaCy tokens use dep_ (with underscore) to get dependency label as string; dep without underscore returns an integer ID.
  2. Step 2: Verify code correctness

    Code uses token.dep which prints integer IDs, not readable labels; likely intended to print labels, so underscore is missing.
  3. Final Answer:

    Missing underscore in token.dep_ attribute -> Option C
  4. Quick Check:

    Use token.dep_ for labels, not token.dep [OK]
Hint: Use token.dep_ (with underscore) for readable labels [OK]
Common Mistakes:
  • Using token.dep instead of token.dep_
  • Assuming doc is wrong type
  • Thinking print syntax is incorrect
5. You want to extract all verbs and their direct objects from a sentence using dependency parsing. Which approach is best?
hard
A. Use only token text without parsing dependencies
B. Find tokens with POS tag 'VERB' and check their children with dependency label 'dobj'
C. Extract tokens with POS tag 'NOUN' ignoring dependencies
D. Select tokens with dependency label 'nsubj' only

Solution

  1. Step 1: Understand task requirements

    We want verbs and their direct objects, so we need to find verbs and check which tokens depend on them as direct objects (dobj).
  2. Step 2: Evaluate options

    Find tokens with POS tag 'VERB' and check their children with dependency label 'dobj' correctly finds verbs and their dobj children. Others ignore dependencies or focus on subjects or nouns only.
  3. Final Answer:

    Find tokens with POS tag 'VERB' and check their children with dependency label 'dobj' -> Option B
  4. Quick Check:

    Verbs + dobj children = correct extraction [OK]
Hint: Look for verbs and their dobj children in dependency tree [OK]
Common Mistakes:
  • Ignoring dependency labels
  • Selecting only subjects
  • Using POS tags without dependencies