Challenge - 5 Problems
NER with NLTK Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this NER chunking code?
Given the following Python code using NLTK for Named Entity Recognition (NER), what is the output?
NLP
import nltk from nltk import word_tokenize, pos_tag, ne_chunk sentence = "Apple is looking at buying U.K. startup for $1 billion" tokens = word_tokenize(sentence) pos_tags = pos_tag(tokens) chunks = ne_chunk(pos_tags) print(list(chunks))
Attempts:
2 left
💡 Hint
Look at how NLTK labels named entities like organizations and geopolitical entities.
✗ Incorrect
NLTK's ne_chunk labels 'Apple' as an ORGANIZATION and 'U.K.' as a GPE (Geopolitical Entity). The output is a list mixing Tree objects for entities and tuples for other tokens.
🧠 Conceptual
intermediate1:30remaining
Which NLTK function performs POS tagging before NER?
In the NLTK pipeline for Named Entity Recognition, which function is responsible for assigning part-of-speech tags to tokens before chunking?
Attempts:
2 left
💡 Hint
POS tags describe the role of each word like noun or verb.
✗ Incorrect
pos_tag() assigns part-of-speech tags to tokens, which ne_chunk() then uses to identify named entities.
❓ Hyperparameter
advanced1:30remaining
What is the effect of using binary=True in ne_chunk()?
In NLTK's ne_chunk function, setting binary=True changes the output. What does this parameter do?
Attempts:
2 left
💡 Hint
Think about simplifying entity categories.
✗ Incorrect
binary=True groups all named entities under a generic 'NE' label, ignoring specific types like ORGANIZATION or GPE.
🔧 Debug
advanced2:00remaining
Why does this NER code raise a LookupError?
Consider this code snippet:
import nltk
sentence = "Google is a tech giant"
tokens = nltk.word_tokenize(sentence)
pos_tags = nltk.pos_tag(tokens)
chunks = nltk.ne_chunk(pos_tags)
When running, it raises a LookupError about missing 'maxent_ne_chunker'. What is the cause?
Attempts:
2 left
💡 Hint
Check if all required NLTK models are installed.
✗ Incorrect
NLTK requires the 'maxent_ne_chunker' model to perform named entity chunking. If not downloaded, it raises LookupError.
❓ Model Choice
expert2:30remaining
Which NLTK model is used internally by ne_chunk for NER?
NLTK's ne_chunk function uses a pre-trained model internally. Which model does it use for Named Entity Recognition?
Attempts:
2 left
💡 Hint
Consider the training data NLTK mentions for ne_chunk.
✗ Incorrect
NLTK's ne_chunk uses a Maximum Entropy classifier trained on the ACE corpus for NER.