Bird
Raised Fist0
NLPml~20 mins

Part-of-speech tagging 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
🎖️
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.

Practice

(1/5)
1. What is the main purpose of part-of-speech tagging in natural language processing?
easy
A. To label each word with its grammatical role in a sentence
B. To translate text from one language to another
C. To count the number of words in a sentence
D. To generate new sentences automatically

Solution

  1. Step 1: Understand the role of part-of-speech tagging

    Part-of-speech tagging assigns labels like noun, verb, adjective to each word, showing its grammatical role.
  2. Step 2: Compare with other options

    Translation, word counting, and sentence generation are different NLP tasks unrelated to POS tagging.
  3. Final Answer:

    To label each word with its grammatical role in a sentence -> Option A
  4. Quick Check:

    POS tagging = labeling word roles [OK]
Hint: POS tagging means labeling words by their grammar role [OK]
Common Mistakes:
  • Confusing POS tagging with translation
  • Thinking POS tagging counts words
  • Assuming POS tagging generates sentences
2. Which Python code correctly uses NLTK to perform part-of-speech tagging on the sentence 'I love AI'?
easy
A. import nltk nltk.pos_tag(['I', 'love', 'AI'])
B. import nltk nltk.tag_pos(['I', 'love', 'AI'])
C. import nltk nltk.pos_tag('I love AI')
D. import nltk nltk.pos_tag(['I love AI'])

Solution

  1. Step 1: Check correct function and input type

    The correct function is pos_tag and it expects a list of words, not a string.
  2. Step 2: Analyze each option

    import nltk nltk.pos_tag(['I', 'love', 'AI']) uses pos_tag with a list of words, which is correct. import nltk nltk.tag_pos(['I', 'love', 'AI']) uses a wrong function name. import nltk nltk.pos_tag('I love AI') passes a string instead of a list. import nltk nltk.pos_tag(['I love AI']) passes a list with one string, not separate words.
  3. Final Answer:

    import nltk nltk.pos_tag(['I', 'love', 'AI']) -> Option A
  4. Quick Check:

    pos_tag + list of words = correct syntax [OK]
Hint: Use pos_tag with a list of words, not a single string [OK]
Common Mistakes:
  • Passing a string instead of a list
  • Using incorrect function name
  • Passing a list with one combined string
3. What is the output of the following Python code using NLTK's pos_tag?
import nltk
sentence = ['She', 'runs', 'fast']
tagged = nltk.pos_tag(sentence)
print(tagged)
medium
A. [('She', 'DT'), ('runs', 'VB'), ('fast', 'RB')]
B. [('She', 'NN'), ('runs', 'NN'), ('fast', 'JJ')]
C. [('She', 'PRP'), ('runs', 'VBZ'), ('fast', 'RB')]
D. [('She', 'PRP'), ('runs', 'VBD'), ('fast', 'RB')]

Solution

  1. Step 1: Understand POS tags for each word

    'She' is a pronoun (PRP), 'runs' is a verb in present tense third person singular (VBZ), 'fast' is an adverb (RB).
  2. Step 2: Match tags with options

    [('She', 'PRP'), ('runs', 'VBZ'), ('fast', 'RB')] matches these tags exactly. Other options have incorrect tags like noun (NN), determiner (DT), or past tense verb (VBD).
  3. Final Answer:

    [('She', 'PRP'), ('runs', 'VBZ'), ('fast', 'RB')] -> Option C
  4. Quick Check:

    Pronoun + present verb + adverb = [('She', 'PRP'), ('runs', 'VBZ'), ('fast', 'RB')] [OK]
Hint: Know common POS tags: PRP=pronoun, VBZ=verb present, RB=adverb [OK]
Common Mistakes:
  • Confusing verb tenses VBZ vs VBD
  • Mixing pronouns with nouns
  • Mislabeling adverbs as adjectives
4. The following code throws an error. What is the most likely cause?
import nltk
sentence = 'He is happy'
tagged = nltk.pos_tag(sentence)
print(tagged)
medium
A. The nltk module is not imported correctly
B. The sentence variable should be a tuple, not a string
C. pos_tag requires a second argument specifying the language
D. The input to pos_tag should be a list of words, not a string

Solution

  1. Step 1: Check input type for pos_tag

    pos_tag expects a list of words, but here a single string is passed, which causes an error.
  2. Step 2: Verify other options

    nltk is imported correctly, pos_tag does not require a language argument, and input as tuple is not required.
  3. Final Answer:

    The input to pos_tag should be a list of words, not a string -> Option D
  4. Quick Check:

    pos_tag input must be list, not string [OK]
Hint: Always pass a list of words to pos_tag, not a string [OK]
Common Mistakes:
  • Passing a string instead of a list
  • Assuming pos_tag needs language argument
  • Confusing input types (tuple vs list)
5. You want to tag parts of speech in a sentence but also handle unknown words gracefully. Which approach best improves POS tagging accuracy for new words?
hard
A. Manually assign tags to each unknown word before tagging
B. Use a POS tagger with a built-in model trained on large diverse text
C. Ignore unknown words during tagging to avoid errors
D. Replace unknown words with a fixed placeholder before tagging

Solution

  1. Step 1: Understand handling unknown words in POS tagging

    Taggers trained on large, diverse datasets can predict tags for new words based on context and patterns.
  2. Step 2: Evaluate other options

    Manually tagging unknown words is impractical, ignoring them loses information, and replacing with placeholders removes context.
  3. Final Answer:

    Use a POS tagger with a built-in model trained on large diverse text -> Option B
  4. Quick Check:

    Robust model with training data handles unknown words best [OK]
Hint: Choose taggers trained on big data to handle new words well [OK]
Common Mistakes:
  • Trying to manually tag unknown words
  • Ignoring unknown words instead of tagging
  • Replacing words loses sentence meaning