Maik Skoddow
Tera Patron
Tera Patron

MaikSkoddow_2-1705150749628.png

 

Sentiment Analysis is part of Task Intelligence, which is part of the Customer Service Management (CSM) module. But what if you want to leverage some use cases for sentiment analysis without having the right subscription?

 

During my research, I stumbled across a blog post from ServiceNow announcing the introduction of the sn_nlp_sentiment.SentimentAnalyser() API in the London release. That means there has been an option for sentiment analyses since a long time!

 

 

 

What is Sentiment Analysis?

 

Sentiment analysis, also referred to as opinion mining, is a natural language processing (NLP) technique that involves identifying the sentiment or emotion expressed in a text. The objective of sentiment analysis is to comprehend the subjective information conveyed in the text, such as whether the expressed opinion is positive, negative, or neutral.

 

 

 

Uses Cases

 

Automating sentiment analysis of large volumes of text data can provide valuable insights into opinions, customer satisfaction, and overall sentiment trends. This technique is an important addition to the field of text analytics and plays a significant role in understanding and responding to the sentiments expressed by users in a variety of contexts.

 

Sentiment analysis can be applied to customer support interactions, including emails, chat transcripts, and service tickets. This allows organizations to identify customer satisfaction levels, detect potential issues, and improve the quality of customer service.

 

Companies may analyse employee feedback and engagement surveys to understand the overall sentiment of the workforce, identifying areas for improvement and implementing measures to increase employee satisfaction.

 

 

 

Incorporating an NLU API

 

The sn_nlp_sentiment.SentimentAnalyser() API provided by Sentiment Analysis plugin (ID  com.snc.sentiment_analysis) does not perform the analysis by its own but leverages any 3rd party API for natural language understanding. 

 

Selecting the appropriate provider can be challenging due to the multitude of options available, each with varying prices and offerings. That's why the following list only represents a small selection without any rating.

 

IBM Watson Natural Language Understanding
IBM Watson offers a comprehensive NLU API that includes features such as sentiment analysis, entity recognition, emotion analysis, and keyword extraction.

 

Google Cloud Natural Language API

Google Cloud provides a Natural Language API that enables developers to analyse and extract information from text. It includes sentiment analysis, entity recognition, and syntax analysis.

 

Microsoft Azure Text Analytics

Microsoft Azure offers Text Analytics API, which includes sentiment analysis, key phrase extraction, language detection, and named entity recognition.

 

Amazon Comprehend

Amazon Comprehend is a natural language processing service provided by AWS. It includes features like sentiment analysis, entity recognition, key phrase extraction, and language detection.

 

MonkeyLearn:

MonkeyLearn offers a cloud-based text analysis API that allows developers to build custom models for tasks such as sentiment analysis, classification, and entity recognition.

 

NLP Cloud

NLP Cloud provides a range of NLU APIs, including sentiment analysis, entity recognition, and language detection. It supports multiple languages and is designed for easy integration.

 

MeaningCloud

MeaningCloud offers a Text Analytics API with features such as sentiment analysis, entity recognition, and categorization. It supports multiple languages and industry-specific models.

 

Lexalytics

Lexalytics offers Semantria, a cloud-based text and sentiment analysis API. It provides features like sentiment analysis, entity recognition, and theme extraction.

 

 

 

Set up the Google Cloud Natural Language API

 

Since I personally have always preferred Google services, it was obvious to use this API. Google has a 90-day trial offer with a $300 budget that can be used free of charge for all Google Cloud offerings.

 

There is an excellent article I followed to set up everything and generate an API key, which is required for the second step: https://medium.com/google-cloud/sentiment-analysis-using-google-cloud-machine-learning-552be9b9c39b 

 

MaikSkoddow_0-1705135512695.png

 

 

Configure API connector in ServiceNow

 

After entering "sentiment" into the application navigator, you'll get returned some modules from the sentiment analysis plugin. Choose "Sentiment Connector Configuration". The plugin comes with three predefined configurations, among others for Google:

 

MaikSkoddow_2-1705135897207.png

 

 

Activate the connector and then go directly to the "Credential Alias" record. In its related list "Connections", you will find the reference for the credential record that has to be opened:

 

MaikSkoddow_3-1705136152220.png

 

 

Here, you can now insert the API key in the corresponding field:

 

MaikSkoddow_4-1705136252796.png

 

That's all!

 

 

 

Performing the Sentiment Analysis

 

Determining the sentiment of a given is pretty simple. First, the analyser object has to be instantiated:

 

 

var sa = new sn_nlp_sentiment.SentimentAnalyser();

 

 

And with the method analyze(String inputText) you will be returned with a JSON-based data structure that contains some information, like the most interesting score:

 

MaikSkoddow_7-1705137019804.png

 

 

If the score is less than zero, the sentiment is negative, and the sentiment is positive with a score greater than zero.

 

 

 

Sentiment Analysis in different Languages

 

The sn_nlp_sentiment.SentimentAnalyser() object provides another method analyzeWithLanguage(String inputText, String language) which allows passing a language code as a two-character string like "en", "de" or "fr".

 

This opens up the completely new possibility of analyzing texts from the most common languages. But how do you know which language a text is in? This is where again an NLU provider comes into play, which usually also offers an API for language detection.

 

However, ServiceNow itself already provides a language detection interface, and therefore it's not required to leverage the Google Cloud API again (although it would be possible). The language detection is part of the plugin "Dynamic Translation" (ID com.glide.dynamic_translation), which has to be installed first. For information on this plugin and additional information on Dynamic Translation, refer to the documentation.

 

After entering "dynamic translation" into the Application Navigator, go to "Translator Configurations" and set for the record "ServiceNow" its fields "Active" & "Mark as default for detection" to "true" (if not already done).

 

MaikSkoddow_1-1705149004119.png

 

 

You can leverage the static method:

 

 

sn_dt_api.DynamicTranslation.getDetectedLanguage(String text)

 

 

to detect the language of the passed text.

 

The JSON-based data object includes the detected language in the 'code' field and a corresponding confidence value. A value of "1" corresponds to 100%. In the following example, the text is given in German:

 

MaikSkoddow_0-1705148724467.png

 

In the response payload, there is also an array of alternative language detections available, which might also match. For all possible parameters and a detailed explanation of the returned payload, please refer to the corresponding API documentation

 

The combination of language detection and sentiment analysis opens up a range of possibilities across various applications and industries. It allows organizations to gain a deeper understanding of textual data, leading to better decision-making, improved customer relations, and a nuanced understanding of sentiments across diverse linguistic landscapes.

 

 

 

Costs

 

Although ServiceNow does not charge any additional fees, the external service provider incurs costs for operating the required infrastructure, which are passed on to the user when the corresponding APIs are used.

 

Below is a screenshot of the pricing chart for Google Cloud. The Language Detection API is generally free to use, while the Sentiment Analysis API is only charged for 5000 or more requests. Additionally, there are graduated prices, meaning that the cost per request decreases as the number of requests increases.

 

MaikSkoddow_0-1705234342670.png

 

 

Before utilizing a fee-based external API, it is important to consider implementing a mechanism that limits the maximum number of requests per time unit. This will prevent faulty code from driving up costs unnoticed.

Comments
Martin Ivanov
Giga Sage
Giga Sage

Another great article, @Maik Skoddow ! Thank you!

 

Bookmarked, of course.

Version history
Last update:
‎01-14-2024 04:36 AM
Updated by:
Contributors