For Challenge #5 of the ‘25 days of Serverless’ challenge, we are to implement a solution to help Santa decide if each child is nice or naughty based on what he/she said.
For this solution, we can use Azure Functions which will call Azure Cognitive Services to do sentiment analysis!
Create an Azure Cognitive Services - Text Analytics resource. There is the option to choose a **‘Free’ Pricing Tier if this is the first Text Analytics resource in the region.
Once resource is created, click on ‘Keys and Endpoint’ tab. Copy one of the 2 keys provided.
Access this to try out calling the Text Analytics ‘Sentiment API’. Click on the region where your Text Analytics resource is created.
On click, paste the copied key from Step 2 to the Ocp-Apim-Subscription-Key field. Click on ‘Send’ to make request.
If successful, there should be a HTTP 200 Response followed by a sample response. As can be seen in the response, there is a ‘Sentiment’ field which can use for our purpose. The values will either be of Positive, Neutral or Negative.
- Next step will be to analyze Santa’s list of sentences from the children which we can obtain from https://aka.ms/holiday-wishes.
It comprises of a list of sentences where:
- Each sentence is made up of a child and what he/she says.
- Each sentence is of different language other than language.
- Each child can have multiple sentences
- With the above, we can come up with a simple Azure Function where Santa can call which:
- Calls https://aka.ms/holiday-wishes to get list of sentences
- For each sentence:
- Call Language Detection API - To detect language
- Call Sentiment API - Where Parameters are the language detected + sentence
- Retrieve the ‘Sentiment’ value from Sentiment API response
- Store the value in a simple Dictionary where each key belongs to each child, where value is a Integer score.
- Do a simple calculation logic, where if:
- Positive sentiment - Add 1
- Negative sentiment - Minus 1
- Neutral - Do Nothing
- Generate and return response
Here is the Azure Function solution I created in C#.
- Also to note, there were a couple of hiccups I faced along the way:
- There are 2 versions of Text Analytics at time of writing: v2.1 and v3.0. I used v3.0 which seemed easier to implement.
- However v3.0 has some limitations such as no support of Swedish language which was one of the languages present in the provided sentences.
Thought this was a fun project to explore world of Azure AI Services with. Do try it out!
Also realized I missed out on doing Day 4. Will do Day 4 next.
Alibaba ACA Cloud Computing Certification Study Guide
DataTable JQuery Plugin - "DataTable is not a function" error