0
0
NLPml~20 mins

Part-of-speech tagging in NLP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
POS Tagging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the main goal of part-of-speech tagging?

Imagine you have a sentence and you want to label each word with its role, like noun or verb. What is the main goal of part-of-speech tagging in this context?

ATo count the number of words in the sentence.
BTo translate the sentence into another language word by word.
CTo assign each word in a sentence its grammatical category such as noun, verb, adjective, etc.
DTo remove all punctuation marks from the sentence.
Attempts:
2 left
💡 Hint

Think about labeling words with their roles in a sentence.

Predict Output
intermediate
2:00remaining
Output of POS tagging with NLTK

What is the output of this Python code using NLTK for POS tagging?

NLP
import nltk
nltk.download('averaged_perceptron_tagger')
sentence = 'The quick brown fox jumps over the lazy dog'.split()
tagged = nltk.pos_tag(sentence)
print(tagged)
A[('The', 'DT'), ('quick', 'NN'), ('brown', 'VB'), ('fox', 'JJ'), ('jumps', 'NN'), ('over', 'IN'), ('the', 'DT'), ('lazy', 'NN'), ('dog', 'VB')]
B[('The', 'DT'), ('quick', 'JJ'), ('brown', 'JJ'), ('fox', 'NN'), ('jumps', 'VBZ'), ('over', 'IN'), ('the', 'DT'), ('lazy', 'JJ'), ('dog', 'NN')]
C[('The', 'PRP'), ('quick', 'RB'), ('brown', 'NN'), ('fox', 'NN'), ('jumps', 'NN'), ('over', 'IN'), ('the', 'DT'), ('lazy', 'JJ'), ('dog', 'VB')]
D[('The', 'NN'), ('quick', 'VB'), ('brown', 'NN'), ('fox', 'VB'), ('jumps', 'NN'), ('over', 'VB'), ('the', 'NN'), ('lazy', 'VB'), ('dog', 'NN')]
Attempts:
2 left
💡 Hint

Look for common POS tags: DT (determiner), JJ (adjective), NN (noun), VBZ (verb, 3rd person singular present), IN (preposition).

Model Choice
advanced
2:00remaining
Best model type for accurate POS tagging on new text

You want to build a part-of-speech tagger that works well on new sentences it has never seen before. Which model type is generally best for this task?

AA neural network model trained on a large annotated corpus with word embeddings
BA simple frequency-based tagger that assigns the most common tag per word
CA rule-based system with manually written grammar rules
DA random tagger that assigns tags randomly to each word
Attempts:
2 left
💡 Hint

Think about models that learn patterns from lots of examples and generalize well.

Metrics
advanced
1:30remaining
Which metric best measures POS tagging accuracy?

After training a POS tagger, you want to evaluate how well it labels words correctly. Which metric is most appropriate?

APrecision of predicted tags over all words
BF1 score of predicted tags ignoring true negatives
CRecall of predicted tags over all words
DOverall accuracy: percentage of words tagged correctly
Attempts:
2 left
💡 Hint

Think about how many words got the right tag out of all words.

🔧 Debug
expert
2:30remaining
Why does this POS tagging code raise an error?

Consider this code snippet using spaCy for POS tagging. Why does it raise an AttributeError?

NLP
import spacy
nlp = spacy.load('en_core_web_sm')
doc = nlp('I love machine learning')
for token in doc:
    print(token.pos)
ABecause <code>token.pos</code> is a property but returns an integer code, not a string tag
BBecause <code>token.pos</code> is a method and needs parentheses to be called
CBecause the model <code>en_core_web_sm</code> is not installed
DBecause <code>token.pos</code> does not exist; the correct attribute is <code>token.tag</code>
Attempts:
2 left
💡 Hint

Check the spaCy documentation for token.pos and what it returns.