Sentiment Analysis — with Salesforce Einstein.

Sameer Khan
4 min readOct 29, 2019

SENTIMENT ANALYSIS — know your customer’s emotions.

Introduction :
Artificial Intelligence (AI) is already part of our lives. Whenever you pick up your smartphone, you’re already seeing what AI can do for you, from tailored recommendations to relevant search results.

So, What Is AI?
At a high level, AI is the concept of having “machines think like humans.”
You’re starting to see examples of AI in your everyday life because we’re at an evolutionary tipping point.

AI & CRM

We already know that machine learning algorithms can understand how human agents diagnose and solve customer problems by learning from historical data over time.AI has benefits for all parts of the business whether it be Sale, Service or Marketing.

Some of the Examples:
1)Sales reps no longer have to enter sales data manually.
2)Marketers no longer have to use manual A/B testing to select the best social media images for their next campaign.
3)And customer service managers no longer have to sift through long lists of incoming service calls to prioritize their time.

With the current technology world talking about AI. Salesforce has come up with is own AI Platform call, Salesforce Einstein. That provides us various products like:

  1. Einstein Vision
  2. Einstein Prediction Builder
  3. Einstein Next Best Action
  4. Einstein Language

But today what we are going to learn about is Einstein Language.

Einstein Language contains two NLP services: Einstein Intent and Einstein Sentiment.

Einstein Intent — The Einstein Intent API categorizes unstructured text into user-defined labels to better understand what users are trying to accomplish.

Use case:

Determine which products prospects are interested in, and send customer inquiries to the appropriate salesperson.
Route service cases to the correct agents or departments, or provide self-service options.
Understand customer posts to provide personalized self-service in your communities.

Einstein Sentiment — The Einstein Sentiment API classifies text into positive, negative, and neutral classes to understand what the words people use can tell us about how they’re feeling.

Use Case :

Identify the sentiment or emotion in a prospect’s emails to trend a lead or opportunity up or down.
Provide proactive service by helping dissatisfied customers first or extending promotional offers to satisfied customers.
Monitor how people perceive your brand across social media channels, identify brand evangelists and note customer satisfaction.

What we are doing :

We are trying to get the sentiments of the Case that is inserted in the system.

How to implement :

To Implement Einstine Language there are some prerequisite steps :

Before you can access the Einstein Platform Services APIs, you first need to create an account and download your RSA key. Then you use your key to generate an OAuth token.

  1. Navigate to the sign-up page at https://api.einstein.ai/signup. You will get a private RSA key it can be downloaded as ‘einstein_platform.pem’
  2. Use the Private key generated(save this file as this is important to get access token) to get the token https://api.einstein.ai/token.
  3. We can use Apex Class to get a live token by using JWT.apex and JWTBearer.apex class. (I am using token I got from the above link)
  4. You can get the classes here https://github.com/salesforceidentity/jwt
  5. Create a Remote Site Setting with URL: https://api.einstein.ai
  6. API: https://api.einstein.ai/v2/language/sentiment
  7. You can find the details of the above steps here: https://metamind.readme.io/docs/what-you-need-to-call-api

What we did:

There is one field on case object called ‘Description’ we are using this as customer’s feedback.
We have created a Lightning Component ‘getSentiments’ and calling it with Quick Action ‘getCustomerSentiments’ the button will send the text in the ‘Description’ field to the SOAP Services which would then analyze the text and return the Sentiment of the text. We have used a formula field Sentiment Analysis to get the image on the basis of sentiments

Wrapper Class to store the response :

global class SentimentResponse {
webservice List<Probabilities> probabilities { get; set; }

global class Probabilities {
webservice String label { get; set; }
webservice Double probability { get; set; }
}
}

We get the reponse in JSON as :
{
“probabilities”: [
{
“label”: “positive”,
“probability”: 0.77945083
},
{
“label”: “negative”,
“probability”: 0.18806243
},
{
“label”: “neutral”,
“probability”: 0.032486767
}
]
}

You can find code for Lightning component and Apex Class here :

https://drive.google.com/drive/folders/10xBRGcCwDUr8hEI5lg29FH6k0a80uR4t?usp=sharing

Demo :

Without Description and Sentiments
With Description and Sentiment after we hit the GetCustomerSentiments button

Future Enhancement :

We can enhance the power of Sentiment Analysis by using Einstein Next Best Action to provide the best possible action that can be taken by your customer representative on the basis of your customer sentiments.

Useful Links :

--

--