Quickly Finding Sentiment Using Azure Text Analytics

by 

| October 6, 2020 | in

Text analysis can potentially be very powerful. The ability to judge text as positive or negative is very interesting. This would obviously be a very powerful tool for analyzing things such as blog comments or product review comments (“Are people giving us positive or negative feedback on our product?”).

So lucky for us, Text Analytics is pretty easy to work within Azure. We can get something up and running with three basic steps.

Create an Azure Service for Text Analytics.

Write some very simple code. This code just needs to create TextAnalyticsClient. Then call AnalyzeSentiment. Yep, it’s that simple.

Then we can look at the results. Azure gives us Positive, Negative, and Neutral results.

Results
Positive: 0.55
Negative: 0.23
Neutral: 0.22

static async Task Main(string[] args)
{
// 1. Install nuget package Azure.AI.TextAnalytics
// 2. Create a client
var client = new TextAnalyticsClient(new System.Uri(endpointText), new AzureKeyCredential(subKeyText));
// 3. Let Azure Analyze the Sentiment
var result = await client.AnalyzeSentimentAsync(@"One of our goals at Don’t Panic Labs is to become a shining example of what
professional software engineering looks like. This is a lofty goal. I define “professional” by comparing
the expectations people have for software developers to those of other recognized professions such as
doctors, lawyers, pilots, civil/mechanical/electrical engineers, etc. I think we would all agree that
our industry has a long way to go before the general public has the same faith in us as they do with
doctors or airline pilots. But this should be our goal, and it is our goal at Don’t Panic Labs. It is my
firm belief that our ability to achieve the type of agility I described above will correspond directly
with our ability to deliver “professional” expectations. So how do we get there? It is certainly a
journey, as opposed to a destination. In the development teams I have been a part of, the one thing I
have valued is their ability to see processes and methodologies as tools to achieve desired outcomes.
At Don’t Panic Labs, we have assimilated many disparate techniques, but have done so in a lean,
lightweight way. We prove the value of a process and then determine where the point of diminishing
return is and don’t go beyond it. So where do I start? The advice I would give folks is to sit down and
enumerate the outcomes they desire, prioritize these, and then intentionally and deliberately adopt and
adapt processes to achieve these outcomes. You can use the list above as a starting point. Keep in mind
that you may not see profound results right away (remember there are multiple dimensions to agility and
no silver bullet). The key is to continue to build upon these efforts and layer in new tools and
techniques while reviewing the existing tools and techniques.");
// 4. Display the results
Console.WriteLine("Positive: " + result.Value.ConfidenceScores.Positive);
Console.WriteLine("Negative: " + result.Value.ConfidenceScores.Negative);
Console.WriteLine("Neutral: " + result.Value.ConfidenceScores.Neutral);
}
view raw program.cs hosted with ❤ by GitHub

Now, what about using this to look at some political articles. I took the top five CNN articles about Trump and about Biden by searching for “cnn trump” or “cnn biden” on August 10th using Google News.

What can we learn from this?

First off, there isn’t enough data for this to be relevant. We would need to run a lot more articles through our system to get anything relevant. But the one thing we maybe could glean from that is there is a lot of negative political articles out there. Only one of the 10 was positive.

Azure Text Analytics is pretty amazing, and it’s amazingly simple to interact with considering the power it provides. Whether you’re classifying information based on the vocabulary used or gathering customer sentiment, Text Analytics is a welcome tool to have in your toolbox.

author avatar
Chad Michel Senior Software Architect
Chad is a lifelong Nebraskan. He grew up in rural Nebraska and now lives in Lincoln. Chad and his wife have a son and daughter.

Related posts