Named entity recognition (NER) or entity identification is an AI technique that automatically identifies named entities in given text and classifies them into predefined categories. Entities can be names of people, organizations, locations, times, quantities, monetary values, percentages, and more.
Extracting these entities helps businesses easily analyze huge amounts of unstructured data, like open-ended survey responses, emails, social media conversations, and more. This extracted data contains valuable information and insights for business.
Named entity recognition has many different usage, such as text summarization, question answering or data categorization. Like to know relevant pieces of data from incoming support tickets, like company names, product names, or series numbers, making it easier to route tickets to the most suitable agent or team for handling that issue.
Salesforce Einstein API (beta) has capability to recognize named entities. In this post we will see step by step process to extract named entities from text lines.
Below steps will be required to get named entities from given text using Salesforce Einstein API.
- Create account in Einstein Platform Services
- Create Private Key and Generate Token
- Extract Named Entities
- Format response to show in LWC data table
For Step 1 and Step 2 can check our post Create OCR App using Salesforce Einstein OCR API
3. Extract Named Entities
The Einstein NER (beta) named-entity recognition (NER) model returns entities for a given text. This api right now supporting below entities
For each entity, different set of information will return from API. As example, if we request entities for text ‘Marc Benioff, the CEO of Salesforce, gave the keynote speech at the conference in Paris last week.’ We will get below entities
Person : First Name : Marc , Last Name : Benioff
Datetime: Last week
Let us use Einstein Entity API to get entity information. Below are API request detail which need to submitted for getting entity information.
For this let us create apex class EntityDetectionService to call Einstein Entity API.
Based on passed text, we will get response from API.
4. Format response to show in LWC data table
We have response text from Einstein Entity API, let us change that into tabular format. For that we have to parse JSON text into object. Create a response class to hold response data.
In step 3, we have created service class which will get entity information from passed text. Let us call that service class from controller apex class which will be called by LWC component.
Let us create a LWC component which will provide text to extract entity information. This LWC component will use EntityExtractor.getEntityText method. We can use data table component show entity information. I have used only top level information but we can get further information for each entity type like for person type we can get first name, last name etc.