top of page
Writer's pictureThe Tech Platform

How to Perform Named Entity Recognition (NER) in Python

Due to all the potential special cases and other issues, attempting to set up a system for recognizing named entities (NER) can be quite the difficult task in Python. However, by using a Natural Language Processing API, we can provide a reusable solution to the problem in just a few minutes.



First, we need to run this command to install the SDK:

pip install cloudmersive-nlp-api-client

After the installation, we can call the function with the following code:

from __future__ import print_function
import time
import cloudmersive_nlp_api_client
from cloudmersive_nlp_api_client.rest import ApiException
from pprint import pprint

# Configure API key authorization: Apikey
configuration = cloudmersive_nlp_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'

# create an instance of the API class
api_instance = cloudmersive_nlp_api_client.ExtractEntitiesApi(cloudmersive_nlp_api_client.ApiClient(configuration))
value = cloudmersive_nlp_api_client.ExtractEntitiesRequest() # ExtractEntitiesRequest | Input string

try:
    # Extract entities from string
    api_response = api_instance.extract_entities_post(value)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling ExtractEntitiesApi->extract_entities_post: %s\n" % e)

The response will return all entities from the string, including entity type and entity text. To retrieve your API key, visit the Cloudmersive website to register for a free account; this will provide 800 calls/month across any of our APIs.



Source: Medium - Cloudmersive


The Tech Platform

0 comments

Recent Posts

See All

Comments


bottom of page