nltk.ne_chunk returns a nested nltk.tree.Tree object so you would have to traverse the Tree object to get to the NEs.

Take a look at Named Entity Recognition with Regular Expression: NLTK

>>> from nltk import ne_chunk, pos_tag, word_tokenize
>>> from nltk.tree import Tree
>>> 
>>> def get_continuous_chunks(text):
...     chunked = ne_chunk(pos_tag(word_tokenize(text)))
...     continuous_chunk = []
...     current_chunk = []
...     for i in chunked:
...             if type(i) == Tree:
...                     current_chunk.append(" ".join([token for token, pos in i.leaves()]))
...             if current_chunk:
...                     named_entity = " ".join(current_chunk)
...                     if named_entity not in continuous_chunk:
...                             continuous_chunk.append(named_entity)
...                             current_chunk = []
...             else:
...                     continue
...     return continuous_chunk
... 
>>> my_sent = "WASHINGTON -- In the wake of a string of abuses by New York police officers in the 1990s, Loretta E. Lynch, the top federal prosecutor in Brooklyn, spoke forcefully about the pain of a broken trust that African-Americans felt and said the responsibility for repairing generations of miscommunication and mistrust fell to law enforcement."
>>> get_continuous_chunks(my_sent)
['WASHINGTON', 'New York', 'Loretta E. Lynch', 'Brooklyn']


>>> my_sent = "How's the weather in New York and Brooklyn"
>>> get_continuous_chunks(my_sent)
['New York', 'Brooklyn']
Answer from alvas on Stack Overflow
🌐
Artiba
artiba.org › blog › named-entity-recognition-in-nltk-a-practical-guide
Named Entity Recognition in NLTK: A Practical Guide | Artificial Intelligence
Named entity recognition (NER) is an essential part of natural language processing (NLP) that helps to identify particular entities, including names, organizations, and locations within the text.
🌐
Python Programming
pythonprogramming.net › named-entity-recognition-nltk-tutorial
Named Entity Recognition with NLTK
There are two major options with NLTK's named entity recognition: either recognize all named entities, or recognize named entities as their respective type, like people, places, locations, etc.
Top answer
1 of 7
36

nltk.ne_chunk returns a nested nltk.tree.Tree object so you would have to traverse the Tree object to get to the NEs.

Take a look at Named Entity Recognition with Regular Expression: NLTK

>>> from nltk import ne_chunk, pos_tag, word_tokenize
>>> from nltk.tree import Tree
>>> 
>>> def get_continuous_chunks(text):
...     chunked = ne_chunk(pos_tag(word_tokenize(text)))
...     continuous_chunk = []
...     current_chunk = []
...     for i in chunked:
...             if type(i) == Tree:
...                     current_chunk.append(" ".join([token for token, pos in i.leaves()]))
...             if current_chunk:
...                     named_entity = " ".join(current_chunk)
...                     if named_entity not in continuous_chunk:
...                             continuous_chunk.append(named_entity)
...                             current_chunk = []
...             else:
...                     continue
...     return continuous_chunk
... 
>>> my_sent = "WASHINGTON -- In the wake of a string of abuses by New York police officers in the 1990s, Loretta E. Lynch, the top federal prosecutor in Brooklyn, spoke forcefully about the pain of a broken trust that African-Americans felt and said the responsibility for repairing generations of miscommunication and mistrust fell to law enforcement."
>>> get_continuous_chunks(my_sent)
['WASHINGTON', 'New York', 'Loretta E. Lynch', 'Brooklyn']


>>> my_sent = "How's the weather in New York and Brooklyn"
>>> get_continuous_chunks(my_sent)
['New York', 'Brooklyn']
2 of 7
22

You can also extract the label of each Name Entity in the text using this code:

import nltk
for sent in nltk.sent_tokenize(sentence):
   for chunk in nltk.ne_chunk(nltk.pos_tag(nltk.word_tokenize(sent))):
      if hasattr(chunk, 'label'):
         print(chunk.label(), ' '.join(c[0] for c in chunk))

Output:

GPE WASHINGTON
GPE New York
PERSON Loretta E. Lynch
GPE Brooklyn

You can see Washington, New York and Brooklyn are GPE means geo-political entities

and Loretta E. Lynch is a PERSON

🌐
Medium
fouadroumieh.medium.com › nlp-entity-extraction-ner-using-python-nltk-68649e65e54b
NLP Entity Extraction/NER using python NLTK | by Fouad Roumieh | Medium
October 13, 2023 - Now, we have the tagged_tokens ... step for named entity recognition, let’s see the final step which is the actual Entity Extraction. To extract the entities all we need is to call “ne_chunk” to chunk the given list of tagged tokens: entities = nltk.ne_chunk(tagg...
🌐
Medium
medium.com › data-science › named-entity-recognition-with-nltk-and-spacy-8c4a7d88e7da
Named Entity Recognition with NLTK and SpaCy | by Susan Li | TDS Archive | Medium
December 6, 2018 - With the function nltk.ne_chunk(), we can recognize named entities using a classifier, the classifier adds category labels such as PERSON, ORGANIZATION, and GPE. ne_tree = ne_chunk(pos_tag(word_tokenize(ex))) print(ne_tree) ...
🌐
Nanonets
nanonets.com › blog › named-entity-recognition-with-nltk-and-spacy
A complete guide to Named Entity Recognition (NER) in 2025
January 20, 2025 - In this section, we’ll be using ... ... nltk is a leading python-based library for performing NLP tasks such as preprocessing text data, modelling data, parts of speech tagging, evaluating models and more....
🌐
MLK
machinelearningknowledge.ai › home › beginner’s guide to named entity recognition (ner) in nltk library
Beginner's Guide to Named Entity Recognition (NER) in NLTK Library - MLK - Machine Learning Knowledge
June 2, 2021 - In the output, we can see that the classifier has added category labels such as PERSON, ORGANIZATION, and GPE (geographical physical location) where ever it founded named entity. ... import nltk from nltk import word_tokenize,pos_tag text = "NASA awarded Elon Musk’s SpaceX a $2.9 billion contract to build the lunar lander." tokens = word_tokenize(text) tag=pos_tag(tokens) print(tag) ne_tree = nltk.ne_chunk(tag) print(ne_tree)
🌐
Spot Intelligence
spotintelligence.com › home › how to implement named entity recognition in python with spacy, bert, nltk & flair
How To Implement Named Entity Recognition In Python With SpaCy, BERT, NLTK & Flair
December 26, 2023 - Note that the nltk.ne_chunk() function requires the input text to be tokenized and part-of-speech tagged, which are included in the example above. To use the named entity recognition (NER) functionality of Flair, you will need to have the Flair library installed on your machine. You can install Flair using pip, the Python package manager, with the following command:
Find elsewhere
🌐
NLTK
nltk.org › book › ch07.html
7. Extracting Information from Text
Named entity recognition is a task that is well-suited to the type of classifier-based approach that we saw for noun phrase chunking. In particular, we can build a tagger that labels each word in a sentence using the IOB format, where chunks are labeled by their appropriate type.
🌐
GitHub
gist.github.com › gavinmh › 4735528
Named Entity Extraction with NLTK in Python · GitHub
File "C:\ProgramData\Anaconda3\lib\site-packages\nltk\tree.py", line 202, in _get_node raise NotImplementedError("Use label() to access a node label.") NotImplementedError: Use label() to access a node label. ... @reach2ashish Replace 'node' with 'label' on Line 12 and it will work :) If you're using Python3, you will also have to add additional ( ) around the print statement.
🌐
Wellsr
wellsr.com › python › python-named-entity-recognition-with-nltk-and-spacy
Python Named Entity Recognition with NLTK & spaCy - wellsr.com
August 14, 2020 - In this tutorial, we’re going to show you exactly how to perform named entity recognition using Python’s NLTK and spaCy libraries.
🌐
YouTube
youtube.com › 3d multimedia
Named Entity Recognition with NLTK | NER | Natural Language Processing | NLP | Python |Tutorial 06 - YouTube
In this video, we will learn how to do Named Entity Recognition (NER) with NLTK in Natural Language Processing (NLP) using Python. Named Entity Recognition (...
Published   January 29, 2024
Views   1K
🌐
NLTK
nltk.org › howto › relextract.html
NLTK :: Sample usage for relextract
For example, assuming that we can recognize ORGANIZATIONs and LOCATIONs in text, we might want to also recognize pairs (o, l) of these kinds of entities such that o is located in l. The sem.relextract module provides some tools to help carry out a simple version of this task. The tree2semi_rel() function splits a chunk document into a list of two-member lists, each of which consists of a (possibly empty) string followed by a Tree (i.e., a Named Entity):
🌐
Hex
hex.tech › templates › sentiment-analysis › named-entity-recognition
Named Entity Recognition (with examples) | Hex
Unearth insights from your business text data using Named Entity Recognition (NER). Leverage Python libraries like SpaCy or NLTK, or employ SQL queries for precise entity...
🌐
GeeksforGeeks
geeksforgeeks.org › nlp › named-entity-recognition-in-nlp
Named Entity Recognition in NLP - GeeksforGeeks
April 28, 2025 - Python3 · import nltk # Define the text to be analyzed text = "GeeksforGeeks is a recognised platform for online learning in India" # Tokenize the text into words tokens = nltk.word_tokenize(text) # Apply part-of-speech tagging to the tokens tagged = nltk.pos_tag(tokens) # Apply named entity recognition to the tagged words entities = nltk.chunk.ne_chunk(tagged) # Print the entities found in the text for entity in entities: if hasattr(entity, 'label') and entity.label() == 'ORGANIZATION': print(entity.label(),'-->', ''.join(c[0] for c in entity)) elif hasattr(entity, 'label') and entity.label() == 'GPE': print(entity.label(), '-->',''.join(c[0] for c in entity)) Output: ORGANIZATION --> GeeksforGeeks GPE --> India ·
🌐
Dev3lop
dev3lop.com › home › using python for named entity recognition (ner), a nlp subtask
Using Python for Named Entity Recognition (NER), A NLP Subtask - Dev3lop
October 26, 2023 - To incorporate named entity recognition (NER) into the existing code, you can employ the ne_chunk() function from the nltk.chunk module, which accepts a list of POS-tagged tokens as input and yields a tree of named entities.
🌐
DataCamp
campus.datacamp.com › courses › introduction-to-natural-language-processing-in-python › named-entity-recognition
NER with NLTK | Python
Inside a list comprehension, tag each tokenized sentence into parts of speech using nltk.pos_tag(). Chunk each tagged sentence into named-entity chunks using nltk.ne_chunk_sents().