Articles → NLP → Chunks In NLP

Chunks In NLP






What Is Chunking?





Example




The quick brown fox jumps over the lazy dog




TokenPOS
TheDT
QuickJJ
BrownJJ
FoxNN
JumpsVBZ
OverIN
TheDT
LazyJJ
DogNN




  1. [The quick brown fox] (NP)
  2. [jumps] (VP)
  3. [over the lazy dog] (PP)

Noun Phrase





Verb Phrase






  1. Main verb = jumps
  2. Complement (extra info) = over the lazy dog (a PP)

Prepositional Phrase (PP)






  1. Preposition = over
  2. Object (NP) = the lazy dog

Prerequisite




python.exe -m pip install --upgrade numpy pandas
python.exe -m pip install --upgrade numpy pandas scikit-learn




  1. punkt
  2. 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


Picture showing the output of chunking in NLP



Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, September 2, 2025

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250