Professional Documents
Culture Documents
A Supervised Framework For Sentiment Analysis: A Two-Stage Approach
A Supervised Framework For Sentiment Analysis: A Two-Stage Approach
A Supervised Framework For Sentiment Analysis: A Two-Stage Approach
A Two-Stage Approach
Abstract
Sentiment analysis (SA) is a vital part of natural language
processing (NLP). It involves analyzing textual data to determine
expressed sentiment, be it positive or negative. Transformer-
based models have gained popularity for sentiment prediction
from the text. However, achieving promising results with these
models requires extensive training data and processing power.
Additionally, when using pre-trained transformer models for
sentiment analysis, they do not generate sentiment-specific
text embeddings as they are trained on large general-purpose
corpora. To address these challenges, this paper presents a two-
step framework. Firstly, the framework aims to learn high-level
sentiment-oriented embeddings of text. It generates embeddings
with Siamese Network and compares them based on their
sentiment class using the triplet loss function. This approach
enables the framework to capture distinctions between positive
and negative sentences, ensuring the generation of sentiment-
specific embeddings. Secondly, it incorporates a classification layer
on top of the embedding layer to enhance sentiment classification.
Experimental results showcase the effectiveness of our proposed
framework, surpassing baseline sentiment analysis results on
1. Introduction
2. Background
The field of sentiment analysis has developed around two key activities.
The first involves the development of sentiment-oriented representations
of text, while the second involves identifying sentiment by considering
important features of natural language. Both of these activities are described
in the following subsection.
and patterns from text, which can be valuable in sentiment analysis, where
certain word combinations or phrases may carry specific sentiments.
However, the true breakthrough in sentiment analysis came with the
advent of transformer-based models. Models such as BERT (Bidirectional
Encoder Representations from Transformers) and GPT (Generative Pre-
trained Transformer) have revolutionized sentiment analysis performance.
Transformers are designed to process the entire input sequence
simultaneously, allowing them to efficiently capture global dependencies
and contextual information. By leveraging extensive pre-trained language
representations and fine-tuning techniques, these models can generate
sentiment predictions and adapt to diverse domains and languages.
Summary of discussion:
In summary, deep learning models require massive data and processing
power to work from scratch for downstream tasks like sentiment analysis.
If pre-trained models (Ke et. al. 2020; Zhou et. al., 2020) are used for
sentiment analysis in their original form, it does not provide a better
sentiment result as they do not consider the sentiment orientation of the text.
Transfer learning techniques are widely used to use pre-trained models for
sentiment analysis. However, it suffers from the problem of generalization.
Also, to the best of our knowledge, updating weight again requires a huge
data and time while the end-to-end model does not assure that models
are developing sentiment-oriented embedding for sentiment analysis. So,
we believe that ensuring the text embedding generated by the model on
relatively small datasets is sentiment-oriented, and training the model on
this sentiment-oriented embedding with a single layer can improve the
accuracy of sentiment identification.
290 Prashantkumar M. Gavali & Suresh K. Shirgave
3. Model architecture
FigureFigure
1. Framework Architecture
1. Framework Architecture
3.2 Encoder
The encoder component of the framework is responsible for generating
the encoding of input text. It is a BERT-like encoder with 6 encoding
units each having 12 attention heads. The primary function of the Encode
component is to preprocess the original input text received from the
Siamese network and convert it into a structured format. It then learns
the context-aware embedding of the text, even when dealing with long
sentences. This enables the framework to capture contextual information
effectively and generate meaningful representations of the input text.
4. Discussion
the distances between individual examples. While margin loss sets a fixed
threshold for class separation, triplet loss refines this concept by using
triplets of two positive, and negative examples, encouraging embeddings to
not only maintain a certain distance between classes but also to emphasize
the relative positioning of each embedding. This makes triplet loss more
adaptable and effective for tasks like embedding learning and similarity
measurement.
The choice of the triplet loss function for our model was motivated by
its efficacy in addressing the challenges inherent in the sentiment analysis
task. Triplet loss is particularly well-suited for tasks involving embedding
generation, where the objective is to pull similar instances closer together
in the embedding space while pushing dissimilar instances apart. In the
proposed model, we also want to get embedding of positive sentence
embedding closer to the other positive sentence embedding, and at the same
time, it should be far apart from the negative sentiment embedding. This
embedding generation setup helps the model to distinguish between positive
and negative sentiment more easily than the mixed positive and negative
sentiment embeddings.
5. Experimental Results
Datasets
The proposed framework uses the dataset for two reasons. (1) For
generating sentiment-oriented embedding (2) For training the model for
sentiment identification task. For sentiment embedding generation, we
have used a sentiment-oriented sentence-labeled dataset (Dimitrios, 2015).
A Supervised Framework for Sentiment Analysis: A Two-Stage Approach 297
Following are some of the reasons for selecting this dataset for generating
sentiment-aware embedding.
•R
elevance: Since the framework is used for sentiment analysis, the
specified dataset is relevant as it contains text data with annotations for
the sentiment.
•Q
uality: The dataset is of high quality as it is without irrelevant and
noisy information. The reviews present in this dataset are clear, concise,
and without spelling and grammar errors.
• Balance: The dataset includes 1500 positive and 1500 negative reviews.
•D iversity: All the reviews present in the dataset are selected from
famous IMDB, Amazon, and Yelp websites. Thus it includes a wide
range of text styles, genres, and topics. This helps to ensure that the
model can generalize well to new and unseen text data.
•A
nnotation Quality: The dataset contains high-quality annotations or
labels.
For the second task, sentiment identification, the following datasets were
used.
1. S
ST-2 (Socher et. al., 2013): The Stanford Sentiment Treebank dataset
is a benchmark dataset commonly used for sentiment analysis tasks. It
consists of movie reviews from the Rotten Tomatoes website, labeled
with either a positive or negative sentiment.
2. IMDB (Maas et. al., 2011): IMDB is a well-known and extensively
used movie review website. This website's user reviews are helpful for
sentiment analysis. The IMDB dataset includes 50,000 movie reviews
taken from the IMDB website. These reviews are categorized as
positive or negative.
298 Prashantkumar M. Gavali & Suresh K. Shirgave
Table 1 summarizes the experimental datasets used in this study. The table
includes columns for the number of training, development, testing, and
total examples, as well as a column indicating the available classes in each
dataset. The final column, "balanced," indicates whether or not each training
class includes an equal number of examples.
Preprocessing
The preprocessing task mainly consists of tokenization, sentence
segmentation, adding special tokens, padding and truncation, and input
encoding. These preprocessing steps help to convert the raw text data into a
format that is suitable for the framework to process and make predictions.
•T
okenization: It breaks down words into smaller sub-words and
characters to handle out-of-vocabulary words. This helps to reduce the
size of the vocabulary, which is essential in large-scale NLP models.
• Sentence segmentation: It splits the input into individual sentences.
•P adding and truncation: The input sequences must be of the same
length, so shorter sequences must be padded with zeros, and longer
sequences must be truncated to a maximum length.
Classifiers
The following classification models are considered to evaluate the impact
A Supervised Framework for Sentiment Analysis: A Two-Stage Approach 299
Evaluation Metrics
Various metrics like accuracy, precision, recall, and f1 score, are available
to assess the sentiment models. Accuracy directly measures the percentage
300 Prashantkumar M. Gavali & Suresh K. Shirgave
5.2 Results
Comparative Sentiment Results
Experiments were carried out to compare the performance of the
proposed framework to that of various benchmark models. Table II shows
sentiment results (Accuracy and F1 score) for Logistic Regression IF-IDF,
Naïve Bays, SVM, LSTM, CNN, and BERT models on the SST-2 and
IMDB datasets. From Table II, it is observed that the proposed model
outperforms the listed model on both datasets. This is because the proposed
two-stage supervised framework develops sentiment-oriented embeddings
and uses the same for sentiment analysis.
Embedding Visualization
The t-SNE (t-distributed Stochastic Neighbor Embedding) (Hinton &
Rowei, 2013) is a commonly used method for visualizing data with high
dimensions in a space with fewer dimensions. Embeddings generated by
the proposed model, in task 1, are visualized using t-SNE. It is useful to
know whether the generated embeddings are sentiment-oriented. For the
comparison, we have also visualized text embedding generated by the
BERT encoder. The text embedding dimensions are reduced to 2 by the
t-SNE algorithm. These dimensions are used to plot the embedding in a
scatter plot graph. The t-SNE algorithm is trained with 450 iterations and
a perplexity of 30. We obtained the two-dimensional embedding graph
as shown in Fig. 2 and Fig. 3. Fig. 2 shows embedding generated by the
BERT model while Fig. 3 shows embedding generated by the proposed
framework.
we have also visualized text embedding generated by the BERT encoder. The text embedding
dimensions are reduced to 2 by the t-SNE algorithm. These dimensions are used to plot the
embedding in a scatter plot graph. The t-SNE algorithm is trained with 450 iterations and a
perplexity of 30. We obtained the two-dimensional embedding graph as shown in Fig. 2 and Fig.
Prashantkumar
302embedding generated
3. Fig. 2 shows by theM.BERT
Gavalimodel
& Suresh K. Shirgave
while Fig. 3 shows embedding generated
by the proposed framework.
Figure 2. Visualization
Figure of textofEmbeddings
2. Visualization in 2-dimensional
text Embeddings Space by BERT
in 2-dimensional Space model
by
BERT model
Figure
Figure 3. 3. Visualization
Visualization of text Embeddings
of text Embeddings in 2-dimensional
in 2-dimensional Space by theSpace by the
proposed model
proposed model
Small circles that are filled in Figure 2 and Figure 3 represent the two-dimensional embedding.
The closely spaced-filled circles signify embeddings that are closer together. Figure 3 shows that
positive text embeddings, represented by purple circles, are closer to each other, while negative
text embeddings, represented by red circles, are also closer to each other. This indicates that
positive and negative embeddings are more coherent and distinct. As expected, text embeddings
are separated based on their sentiment orientation. Negative text representations are more coherent
than positive ones because fewer positive text embeddings are intermixed with negative
representations. However, this is only true for a smaller number of embeddings when compared to
A Supervised Framework for Sentiment Analysis: A Two-Stage Approach 303
Small circles that are filled in Figure 2 and Figure 3 represent the
two-dimensional embedding. The closely spaced-filled circles signify
embeddings that are closer together. Figure 3 shows that positive text
embeddings, represented by purple circles, are closer to each other, while
negative text embeddings, represented by red circles, are also closer to
each other. This indicates that positive and negative embeddings are more
coherent and distinct. As expected, text embeddings are separated based
on their sentiment orientation. Negative text representations are more
coherent than positive ones because fewer positive text embeddings are
intermixed with negative representations. However, this is only true for a
smaller number of embeddings when compared to the original embedding
representation provided by BERT shown in Figure 2. Figure 2 illustrates
that the positive and negative embeddings are located near one another,
suggesting that they do not take into account the sentiment of the text and
do not differentiate the representations based on sentiment.
Table 3. Proximity between sample sentence and other samples using the
proposed model
Expressions such as "I am extremely pleased with this product" and "I
am extremely dissatisfied with this product" convey opposite sentiments
in natural language. Pre-trained BERT models generate sentence
representations that consider the context. However, the high cosine
similarity between these two sentences indicates that text embeddings are
not sentiment-focused. To address this limitation, this paper introduced a
novel two-fold supervised BERT model that developed sentiment-aware
embeddings for text. The text representations were then used as input
for a feedforward neural network, which was designed to determine the
overall sentiment of the given text. A comprehensive investigation was
conducted to assess the effectiveness of intermediate text embeddings
generated for sentiment analysis. The findings indicated that the proposed
model facilitated the development of text embeddings specific to sentiment
orientation and improved the performance of sentiment analysis.
In the future, the framework can be extended further for developing
embedding according to the fine-grained sentiments of text like extremely
positive, positive, neutral, negative, and extremely negative. The new loss
function or different model architecture can help to consider fine levels
of sentiment while generating embeddings. This provision may improve
the result of fine-grained sentiment analysis. Further, the proposed system
can also be extended for handling sarcasm and irony present in the text
while developing sentiment embeddings. In this case, sentences might
have similar structures but use sarcasm, irony, or other forms of indirect
expression. These cases can mislead the system while developing sentiment-
306 Prashantkumar M. Gavali & Suresh K. Shirgave
Acknowledgement The authors would like to thank all those who contributed to the
completion of this research study and paper.
Declarations
References