Chunking › What Is Chunking?

Michael BrenndoerferUpdated March 21, 20263 min read
Language AI HandbookAll chapters
Part 6 of 67Sequence Labeling
Chapter 39Chunking › What Is Chunking?
Reading section 2 of 15 · What Is Chunking? · 3 minSection 2 of 15 · 3 min

Book contents

Section 2 of 15 · 3 min read

Chunking › What Is Chunking?One section · Sections in this chapter2 / 15 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Chunking identifies contiguous spans of tokens that form syntactic units. Unlike full parsing, which produces tree structures with unlimited nesting, chunking produces a flat sequence of labeled segments. Each token belongs to exactly one chunk, or no chunk at all if it falls outside every phrase boundary.

Chunking (Shallow Parsing)

Chunking is the task of grouping consecutive words into non-overlapping, non-recursive phrases such as noun phrases (NP), verb phrases (VP), and prepositional phrases (PP). It identifies phrase boundaries without building hierarchical parse trees, making it faster and less brittle than full syntactic analysis.

The word "shallow" in "shallow parsing" refers to the depth of structural analysis. Chunking reads the surface of a sentence and identifies phrase-like groups, but it does not resolve questions like whether a prepositional phrase modifies the subject or the verb. Those decisions require deeper semantic understanding, and chunking deliberately avoids them.

Consider the sentence "The black cat sat on the mat." A chunker might produce:

  • [The black cat]NP_{NP}, noun phrase (subject)
  • [sat]VP_{VP}, verb phrase (predicate)
  • [on]PP_{PP}, prepositional phrase marker
  • [the mat]NP_{NP}, noun phrase (object of preposition)

The key properties of chunking are:

  • Non-overlapping: Each word belongs to at most one chunk. Two chunks cannot share a token.
  • Non-recursive: Chunks do not contain other chunks of the same type. You won't find an NP inside an NP in a flat chunking annotation.
  • Contiguous: Chunks consist of consecutive words. A chunk cannot span across a gap.
  • Partial coverage: Some words may not belong to any chunk. Articles that introduce a phrase belong to the phrase, but punctuation often remains unchunked.

Let's see chunking in action with NLTK. The ne_chunk function identifies named entities as chunks, which is a specific form of chunking:

In[4]:
Code
from nltk import pos_tag, word_tokenize
from nltk.chunk import ne_chunk

# Download required NLTK resources (comment out after first run)
# nltk.download("punkt", quiet=True)
# nltk.download("averaged_perceptron_tagger", quiet=True)
# nltk.download("maxent_ne_chunker", quiet=True)
# nltk.download("words", quiet=True)
# nltk.download("conll2000", quiet=True)

# Example sentence with named entities
ne_sentence = "Barack Obama visited New York City yesterday."
ne_tokens = word_tokenize(ne_sentence)
ne_tagged = pos_tag(ne_tokens)
ne_chunked = ne_chunk(ne_tagged)
Out[5]:
Console
NLTK Named Entity Chunking
==================================================

Sentence: Barack Obama visited New York City yesterday.

POS Tags:
  Barack       NNP
  Obama        NNP
  visited      VBD
  New          NNP
  York         NNP
  City         NNP
  yesterday    NN
  .            .

Chunk Tree:
(S
  (PERSON Barack/NNP)
  (PERSON Obama/NNP)
  visited/VBD
  (GPE New/NNP York/NNP City/NNP)
  yesterday/NN
  ./.)

NLTK's ne_chunk function returns a tree where named entities appear as labeled subtrees. Each subtree is a chunk. This pattern, where a sequence labeling task produces labeled spans, is the core idea behind all chunking.