Open In App
Related Articles

Aspect Modelling in Sentiment Analysis

Like Article
Save Article
Report issue

Prerequisite: Sentiment Analysis 

Before getting into the specifics of Aspect Modelling, let us first briefly understand what Sentiment Analysis is with a real-life example. 

Sentiment Analysis (SA): 

It is a technique to distinguish a person’s feeling towards something or someone based on a piece of text they have written about it. It could be positive, negative or neutral. Let us consider a real-life example. 

We see millions of tweets on Twitter on a daily basis. Here, we can build a sentiment analysis model to determine if their attitude towards a particular subject is happy, sad, angry or neutral. The current limitations of this technique are detecting sarcasm. 

Aspect Modelling in Sentiment Analysis (ABSA): 

Aspect modelling is an advanced text-analysis technique that refers to the process of breaking down the text input into aspect categories and its aspect terms and then identifying the sentiment behind each aspect in the whole text input. The two key terms in this model are:

  • Sentiments: A positive or negative review about a particular aspect
  • Aspects: the category, feature, or topic that is under observation.


In the business world, there is always a major need to identify to observe the sentiment of the people towards a particular product or service to ensure their continuous interest in their business product. ABSA fulfils this purpose by identifying the sentiment behind each aspect category like food, location, ambience etc. 

This helps businesses keep track of the changing sentiment of the customer in each field of their business. 

ABSA Architecture

The ABSA model includes the following steps in order to obtain the desired output. 

Step 1 -   Consider the input text corpus and pre-process the dataset. 
Step 2 -   Create Word Embeddings of the text input. (i.e. vectorize the text input 
           and create tokens.)
Step 3.a - Aspect Terms Extraction -> Aspect Categories Model 
Step 3.b - Sentiment Extraction -> Sentiment Model 
Step 4 -   Combine 3.a and 3.b to create to get Aspect Based Sentiment.(OUTPUT)


Aspect: It is defined as a concept on which an opinion or a sentiment is based. Let us take an example for better understanding. 

Suppose a company builds a web app that works slow but offers reliable results with high accuracy. Here, we break this text into two aspects. “Web app works slow” and “reliable results with high accuracy“. On observing the two aspect categories, you can easily conclude that they have different sentiment associated with them. (As shown in Fig 1)

Fig 1 : Different Sentiment with different aspects

Code Implementation:

The following code implementation performs the process of aspect extraction and associating it with a particular sentiment to make it model ready for training.


# Importing the required libraries
import spacy
sp = spacy.load("en_core_web_sm")
from textblob import TextBlob
# Creating a list of positive and negative sentences.
mixed_sen = [
  'This chocolate truffle cake is really tasty',
  'This party is amazing!',
  'My mom is the best!',
  'App response is very slow!'
  'The trip to India was very enjoyable'
# An empty list for obtaining the extracted aspects
# from sentences. 
ext_aspects = []
# Performing Aspect Extraction
for sen in mixed_sen:
  important = sp(sentence)
  descriptive_item = ''
  target = ''
  for token in important:
    if token.dep_ == 'nsubj' and token.pos_ == 'NOUN':
      target = token.text
    if token.pos_ == 'ADJ':
      added_terms = ''
      for mini_token in token.children:
        if mini_token.pos_ != 'ADV':
        added_terms += mini_token.text + ' '
      descriptive_item = added_terms + token.text
  ext_aspects.append({'aspect': target,
    'description': descriptive_item})
for aspect in ext_aspects:
  aspect['sentiment'] = TextBlob(aspect['description']).sentiment




Last Updated : 30 May, 2021
Like Article
Save Article
Share your thoughts in the comments
Similar Reads