Articles → NLP → Chunks In NLP
Chunks In NLP
What Is Chunking?
Example
The quick brown fox jumps over the lazy dog
Token | POS |
---|
The | DT |
Quick | JJ |
Brown | JJ |
Fox | NN |
Jumps | VBZ |
Over | IN |
The | DT |
Lazy | JJ |
Dog | NN |
- [The quick brown fox] (NP)
- [jumps] (VP)
- [over the lazy dog] (PP)
Noun Phrase
Verb Phrase
- Main verb = jumps
- Complement (extra info) = over the lazy dog (a PP)
Prepositional Phrase (PP)
- Preposition = over
- Object (NP) = the lazy dog
Prerequisite
python.exe -m pip install --upgrade numpy pandas
python.exe -m pip install --upgrade numpy pandas scikit-learn
- punkt
- averaged_perceptron_tagger
Example
import nltk
from nltk import pos_tag, word_tokenize, RegexpParser
# Sample sentence
sentence = "The quick brown fox jumps over the lazy dog"
# Tokenize and POS tagging
tokens = word_tokenize(sentence)
tagged = pos_tag(tokens)
# Define a simple grammar for noun phrases (NP)
grammar = "NP: {<DT>?<JJ>*<NN>}"
# Create a chunk parser
chunk_parser = RegexpParser(grammar)
# Parse the sentence
tree = chunk_parser.parse(tagged)
print(tree)
Output
Posted By - | Karan Gupta |
|
Posted On - | Tuesday, September 2, 2025 |