Is this presidential campaign more negative than years past? Yes.
How different is this election season than years past? Are this year’s presidential contenders — Hillary Clinton and Donald Trump — more negative than those in the recent past?
I decided to use Google Cloud Natural Language API to analyze speeches made by the nominees of the major American parties in recent years. The University of California at Santa Barbara helpfully puts all the nomination acceptance speeches online, and the NL API is extremely easy to use, so it’s just a matter of hooking up the API with the website.
When you analyze the sentiment of a body of text, you can look at it from two perspectives:
- How positive, neutral or negative is the text? This is called the polarity. Statements about love and happiness will have a positive vibe to them and be given a polarity of 1. Statements about doom and destruction will have a negative vibe and be given a polarity of -1. This being a happy moment in the candidates’ lives, and the fact that they are talking to a friendly crowd, I expected the overall sentiment to be positive.
- How emotional is the text? A speech can be neutral either because it is simply a recitation of facts, or because the positive polarities and negative polarities cancel each other. So, you should look at the sentiment underlying the text on both these dimensions.
Let’s look at the results first. Then, I will show you how you can repeat my analysis.
Party Differences? None
First, there is no major difference between the parties on either polarity or magnitude of emotion:
The mean polarity of Republican speeches is 0.28, as is the mean polarity of Democratic speeches. Republicans are slightly more emotional (36.7) than Democrats (35.8) but that difference is miniscule compared to the variation between speakers.
Everyone is quite emotional. Except Obama 2008
In terms of emotionality, Barack Obama in 2008 (the year he first ran for President) is an outlier. His speech does seem to have been more professorial than is typical in this setting:
President Obama seems to have become much more compelling in 2012. This year, Hillary Clinton hit more highs and lows than did Donald Trump, but they are both well within the typical range of variation.
It is on the polarity dimension that this year is atypical.
This year’s nominees are much more negative than in years past; Donald Trump is literally off the chart
Of course, I saved the most interesting result for last. That is the polarity of the speech. Recall that a polarity of 1.0 is an extremely positive speech; a polarity of -1.0 is an extremely negative and sad speech. The Gettysburg Address, somber and stirring at the same time, comes in around 0.4.
Here is the polarity of recent acceptance speeches by nominees of both parties:
Hillary Clinton and Donald Trump are both noticeably less positive than nominees of years past. In fact, Donald Trump comes in perfectly neutral, at 0.0, which is astonishing considering that he is talking to his supporters who have just nominated him to run for President. In context, this is very, very negative.
How to invoke Google Natural Language API
Just a few lines of Python really — that’s magic of using Machine Learning APIs. The hard work of training the neural network to analyze text has already been done. We get to simply call the API, passing in the text we want analyzed:
url = 'http://www.presidency.ucsb.edu/ws/index.php?pid=118051'
text_of_speech = urllib2.urlopen(url).read()
response = lservice.documents().analyzeSentiment(
'content': unicode(text_of_speech, errors='ignore')
polarity = response['documentSentiment']['polarity']
magnitude = response['documentSentiment']['magnitude']
The complete Python notebook is in github. Feel free to try it out.