
In certain occasions, we might not want to extract the sentiment out of a whole text, but rather predict the sentiment of that text towards a certain entity within it. When this is our goal, traditional sentiment analysis, which returns the overall sentiment of a whole text document, is not enough, and we need to exploit a more complex technique: Targeted Sentiment Analysis. In this post, we will explain the differences between both of them, and illustrate this different behaviour using some very simple examples.
Lets go then!
Hold on, I don’t know what Sentiment Analysis is!
Don’t worry, as always, I am here for you. Sentiment Analysis is a Natural Language Processing (NLP) technique, where given a certain text document as an input, we get the sentiment (positive, negative, and sometimes neutral) of such text as an output. In certain cases we can even get a range of sentiment, like very positive, moderately positive, neutral, moderately negative and very negative.

These models usually come in two different families: Dictionary methods and Machine Learning methods. The former make use of a dictionary of words with positive or negative polarities to infer if a text is positive or negative. This means looking for words like "good", "great", "amazing" , "awesome" , or "love", to see if a text is positive, or words like "bad", "horrible", "terrible", or "hate" to see if a text is negative.
The latter use a large amount of text documents previously labelled as positive or negative to learn from the Data what patterns form positive or negative documents, and then predict the sentiment of new documents by looking for these patterns.
Sentiment analysis has a lot of real use cases: it can be used to track customer sentiment over time for businesses, to infer the likeliness of a product, the opinion of users of a social network towards certain topics, or even for predicting the results of events like presidential campaigns or award ceremonies.
Lets see some example of sentences and sentiment classifications using the Parallel-dots online Sentiment Analysis tool.



As we can see, for each sentence we get a sentiment prediction (positive, neutral or negative) and a confidence in that prediction. The sentiment with the highest confidence is the one that is picked as the underlying feeling of the whole sentence. (In case you are wondering, I did not go to a burger place while this article was being written, but I would have loved to)
As we have seen with these examples, sentiment analysis can be used to extract the overall sentiment from a sentence. However, what happens if we want the sentiment towards a particular entity within a text document, and not the sentiment of the whole text? Consider the following sentence:
"The burger place was good, but my overall day was quite horrible: I got shouted at by my boss, I ate a cookie thinking it was chocolate chip but it was disgusting raisin, and I slipped on the subway."
Imagine we wanted to know the sentiment of the speaker towards The burger place. If we use the same online traditional sentiment analysis tool that we used for the previous sentences, we would get the following result:

As we can see, because the sentence carries an overall negative sentiment, the output of the traditional sentiment analysis is negative even if the sentiment towards The burger place is positive. This is because it is not analysing the specific sentiment towards it, but rather the sentiment of the whole sentence.
If want to analyse the sentiment towards a specific target within a text, we have to use a variant of normal sentiment analysis, known as Targeted Sentiment Analysis.
Targeted Sentiment Analysis: Discovering the sentiment towards…
What targeted sentiment analysis does is basically taking a text and a given entity within that text, and predicting the sentiment reflected on the text towards that entity. In the previous case, given the same sentence, and The burger place as the target entity, a Targeted Sentiment Analysis model would try to predict the sentiment of the speaker towards The burger place, and not the actual sentiment of the entire sentence.
As a Targeted Sentiment Analysis model, I’ve used the Bidirectional LSTM model of Liu and Zhang from"Attention Modeling for Targeted Sentiment", which __ predicts a positive sentiment towards _The burger plac_e with a confidence above 80%. If you don’t know what an LSTM is, you can find it out in my previous post about Deep Learning for NLP.
Okay, that’s cool, but what can Targeted Sentiment Analysis actually be used for? Well, it can perform many of the same tasks as traditional sentiment analysis, and some more complex ones. For example, I used it in a project to analyse the sentiment towards the most important individuals of a certain topic on the Twitter Social Network. I analysed topics like the Brexit or the Oscars, and found out the aggregated opinions of the Twitter users towards certain influential personalities within these topics. Consider the following tweets:
- "I have to say, the Oscars ceremony was horible, lousy presenters, terrible comments, and edgy nominatons, however @ladygaga looked so amazingly beutiful❤ #Oscars"
- " Tonight I could not have more respect for @maitlis on #NewsNight verbally kicking all levels of sht out of every utterly deluded member of parliament inteviewed for triggering A50 leaving us #2weeks till utter diaster. F**k the lot of you. #Brexit"


The first tweet, using a traditional sentiment analyser, returns a negative label with a low confidence, however, if the sentiment towards @ladygaga is analysed using the targeted sentiment analysis model, it returns a positive label with more than 60% confidence. The second tweet, when analysed as a whole, has a very strong overall negative feeling, however, if the sentiment towards @maitilis is analysed with targeted sentiment analysis, we get a positive label again and with a high confidence. Both of these results match what we can see by reading the tweets.
In the project I collected a large set of tweets regarding each topic by filtering for different hashtags, found out who the most mentioned users were (defining them as the most influential personalities within that topic) and calculated the aggregated sentiment of the users of the network towards these influential personalities by using the targeted sentiment analysis model with the tweet’s text and the mentioned user in that text as the target being the inputs for the model.
These kind of approaches can be of great use to businesses, allowing them to go beyond the limitations of traditional sentiment analysis to explore new insights from existing data.
Conclusion
In this post we have seen the differences between traditional sentiment analysis and targeted sentiment analysis, illustrating different scenarios where they could be used.
In the next post we will explore how the different Machine Learning Methods for Sentiment Analysis and Targeted Sentiment analysis work under the hood, digging into their differences with regards to features and models.
Thank you very much for your time, and don’t worry, I don’t need any sentiment analysis to know you are very happy after reading this post 🙂
If you liked it, be sure to follow me on Medium, clap, and feel free to connect with me on LinkedIn or follow me on Twitter at @jaimezorno. Also, you can take a look at my other posts on Data Science and Machine Learning here. Have a good read and take care!
