Show List

Named Entity Recognition

Named Entity Recognition (NER) is a subtask of Natural Language Processing that involves identifying and extracting entities from unstructured text. Entities can be anything from people, places, organizations, to dates, times, and more. NER is widely used in many applications, including information extraction, question answering, and machine translation.

Here is an example of how to perform Named Entity Recognition using the Natural Language Toolkit (NLTK) library in Python:

python
Copy code
import nltk from nltk.tokenize import word_tokenize from nltk.tag import pos_tag from nltk.chunk import ne_chunk text = "John Smith is a software engineer at Google in New York." # Tokenize the text tokens = word_tokenize(text) # Perform part-of-speech tagging on the tokens pos_tags = pos_tag(tokens) # Perform Named Entity Recognition using the part-of-speech tags ne_chunks = ne_chunk(pos_tags) # Extract the named entities from the chunks named_entities = [] for chunk in ne_chunks: if hasattr(chunk, 'label') and chunk.label() == 'NE': named_entities.append(' '.join(c[0] for c in chunk)) print(named_entities)

In this example, we start by importing the necessary NLTK modules. Then, we define a sample text that contains a named entity. Next, we tokenize the text into individual words and perform part-of-speech tagging on the tokens. Finally, we perform Named Entity Recognition using the part-of-speech tags and extract the named entities from the chunks.

The output of the code will be:

css
Copy code
['John Smith', 'Google', 'New York']

which are the named entities identified in the input text.


    Leave a Comment


  • captcha text