Portable Sentiment Analysis with Azure Cognitive Services

Phil Brown 27-Apr-2020 17:52:05

Part 1

In these unprecedented times, how do people keep positive?  I find music is a good way to do so but sometimes even up beat songs have a negative sentiment. We can of course tell the difference - but can your computer?

I thought I could use this as an opportunity to look at Azure Cognitive Services; specifically, sentiment analysis.  Over two blogs I'm going to look at the service itself and how Azure have made it portable.

 

Text Analytics

There are a huge range of Cognitive Services within Azure so today we are looking at just one of them: Text Analytics. Text Analytics provides three elements: raw sentiment analysis, key phrase extraction, and language detection. 

The sentiment analysis gives you the ability to obtain a score between 0 and 1 for any piece of written text.  0 defines an overall negative sentiment and 1 defines a positive sentiment.  

There are loads of ways you can consume the Azure Cognitive services, and I’m going to look at a few in this blog.

 

Test One: The AI Groove 

https://azure.microsoft.com/en-in/services/cognitive-services/text-analytics/

This link itself can be used to analyse text; this is a demo of the API call itself and for this option I’m going to use a classic song 'Groove is in the Heart' by Dee-Lite.  If you know this song then you will know that it is unmistakably positive.  But that’s because you know this song. 

The Text Analytics also sees the sentiment of the song positively so that’s a good start!  Will the other familiar songs we choose also be scored with a positive or negative sentiment that we agree with? Keep reading...         

Azure Text Analytics AI

 

Using Text Analytics

If you would like to deploy Text Analytics and start to use it for development and testing, all you need is an Azure account.  Text Analytics can be consumed under the free tier, not just for the 30 day trial but also for 12 months after, which gives you plenty of time to embed that into a wider application portfolio. 

Creating the Text Analytics service is pretty straight forward.  All you do is give it a name, pricing tier, and resource group.  For the free trial you can use it once per location.

Azure Text Analytics AI

The service takes a few minutes to create and then once it’s been deployed you’re ready to go.  The overview of text analytics within the service console provides links to the APIs. 

Azure Text Analytics AI

The Text Analytics API has four options. The one it defaults to is Detect Language - for the Sentiment analysis you need to select the fourth option down.  To start using the service you need to take a few options from the overview; name (select the resource name rather than generic), resource name, and API key.  To do that it’s a simple copy and paste exercise. 

Azure Text Analytics AI

 

Test Two: Spice it Up

Now I’ve got my one Text Analytics API I will analyse another song; for this one I’ve decided to look at the sentiment of the classic Spice Girls hit 'Wannabe'.  The Text Analytics service measures the sentiment as overwhelmingly positive. 

Azure Text Analytics AI

Now you might think that this is a bit of a no-brainer -why would be it a surprise that this song has a positive sentiment?  You have to remember that even though we know this song and recognise it for its positive upbeat tone, this is an analytics service which correctly interprets the song's sentiment within a few seconds

That’s pretty impressive; it demonstrates the power of the service, the flexibility of Cloud and how it enables us to consume new services without spending weeks and months building the capabilities.

 

What’s even more interesting is that we can take this service and run it anywhere using docker. Don't worry - we will be covering that in Part 2.

 

To read more about how DSP-Explorer are exploring AI technologies, check out our blog predicting the results of the Rugby World Cup: https://content.dsp.co.uk/rugby-world-cup-oracle-machine-learning. You can also get in touch with one of our specialists at enquiries@dsp.co.uk.