Targeted Sentiment Analysis in Watson Studio is Simple and Powerful

Co-authored with: Matan Orbach, Yoav Katz, Noam Slonim

Orith Toledo-Ronen
IBM Data Science in Practice
5 min readDec 12, 2022

--

Customer reviews of businesses and products have become a powerful tool for measuring customer satisfaction. They provide useful insights that help companies improve their services and assist consumers in decision-making.

Sentiment analysis plays a key role in analyzing these reviews. It identifies the sentiment expressed in the text within an entire review document or even in a single sentence. Such document-level or sentence-level analysis provides information on the overall satisfaction level, which can be crucial for a business. Although companies normally rely on a 5-star score or a like/dislike rating, their tools cannot identify the specific sentiment targets beyond the overall rating. They cannot answer such questions as what are the strengths and weaknesses of a certain product? To get these fine-grained details on the sentiment, we need IBM’s Targeted Sentiment Analysis (TSA) technology.

TSA aims to detect the sentiment-bearing terms in texts and classify the sentiment expressed towards them as positive or negative. For example, in the sentence: “The food was good, but the restaurant was very noisy,” there are two targets (‘food’ and ‘restaurant’) with positive and negative sentiments, respectively.

A sentiment target could be the name of a particular company, a product, an aspect of a product (e.g., price, location, or ambiance), or any term with sentiment that appears in the text. The target can be a single word, as in the example above, or multiple words. Multiple targets can be identified in one sentence, each with its own sentiment. Different sentiments for the same target throughout the text can also be identified, for example: “Terrible service and management, but management was kind enough to help with our request.” The target “management” has a negative sentiment in the first occurrence and a positive sentiment in the second one.

IBM’s TSA engine, available in IBM Watson Studio as part of the WatsonNLP module, extracts the targets and their sentiments for a given text in a single call. There is no need to provide the target as part of the input or split the task into two steps of target extraction and sentiment classification.

This technology, which is based on a deep learning multi-lingual BERT Transformer model, is useful for fast analysis of user reviews. The model was trained on English data, but supports other languages with varied levels of performance. Want to get started right away?

These are the four steps you need to complete:

1. Open a free Jupyter notebook in Watson Studio (detailed instructions at the end of this article).

2. Import watson_nlp.

3. Load the WatsonNLP syntax and TSA models.

4. Run the syntax model on some input text and then run the TSA model to get the TSA predictions.

Steps 2–4 can be performed with a few lines of code:

Example 1

Below are the TSA results for the input text “The food was good, but the restaurant was very noisy”. As you can see, both sentiment targets (‘food’ and ‘restaurant’) are identified with their polarity (positive for ‘food’ and negative for ‘restaurant’).

Let’s look at another example. As you can see, our TSA engine can identify multi-word targets such as “front desk service” in the sentence “Great front desk service, these are the things that make me come back every year.”.

Example 2

Now let’s have a look at the analysis of the TSA model on a dataset of hotel reviews with 600 reviews of two hotels. The TSA model extracts the targets from each review. After lemmatizing the extracted targets (target variations like “room”, “rooms” or “Room” may be grouped together), we can identify common sentiment-bearing terms in all of the reviews, and visualize them in a word cloud, as in the image below — with positive sentiment targets on the left and negative sentiment targets on the right.

We can see that ”location” is positive, but ”room” and ”hotel” bear positive and negative sentiments.

Now, what if we want to estimate the quality of each hotel? This can be done easily with the outputs from the TSA model. For example, let’s focus on the 20 most common targets and look at the frequency of the positive and negative mentions of each target in the reviews of each hotel. This analysis is shown in the image below — with blue bars for positive sentiments and red bars for negative sentiments. Now we can start comparing the quality of Hotel A vs. Hotel B in different dimensions.

Need more information? The full documentation of the TSA block describes the API in more detail. Moreover, if you are interested in TSA research, check out our NAACL 2022 paper. For a quick overview on how to run the Watson NLP models in Watson Studio, see Alex Lang’s blog.

Instructions for opening a Jupyter notebook:

1. Log on to https://cloud.ibm.com.

2. Click on “Catalog” and select “Watson Studio”.

3. Select “Lite” (free trial) and click on “Create”.

4. Click on “Launch in IBM Cloud Pak for Data”.

5. Provide your personal information and click on “Continue”.

6. In Projects, click on “New project +” and select “Create an empty project”.

7. Enter a “Project Name” and click on “Add storage device”.

8. Select the “Lite” option and click on “Create”.

9. Open the project, go to the “Assets” tab, and click on “New asset +”.

10. Select “Jupyter notebook editor”.

11. Enter a name for the notebook and select runtime: “DO + NLP Runtime 22.2 on Python 3.10 XS”.

12. Open the notebook and start using Watson NLP (“import watson_nlp”…).

--

--