Advanced Azure Text Analytics API - Text Sentiment Analysis


What is Azure Text Analytics API?

Azure Text Analytics API is a cloud-based service provided by Microsoft Azure that enables advanced text analysis, including sentiment analysis. It can analyze text for sentiment, key phrases, language detection, and more. This API is widely used in various applications, such as social media monitoring, customer feedback analysis, and content recommendation.


Getting Started

To use Azure Text Analytics API for text sentiment analysis, follow these steps:

  1. Sign in to your Azure Portal.
  2. Create a new Azure Text Analytics resource.
  3. Retrieve your API key and endpoint.

Sample Code

Here's a simple example of how to use Azure Text Analytics API in Python for text sentiment analysis:

import requests
import json
subscription_key = 'YOUR_SUBSCRIPTION_KEY'
endpoint = 'YOUR_ENDPOINT'
text = 'I love this product. It works like a charm!'
headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': subscription_key,
}
documents = [{'id': '1', 'language': 'en', 'text': text}]
data = {'documents': documents}
response = requests.post(f'{endpoint}/text/analytics/v3.0/sentiment', headers=headers, json=data)
if response.status_code == 200:
sentiment = response.json()['documents'][0]['sentiment']
print(f'Sentiment: {sentiment}')
else:
print('Error:', response.status_code, response.text)

Conclusion

Azure Text Analytics API simplifies text sentiment analysis and other text analytics tasks, helping you gain insights from text data quickly and efficiently. Whether you need to analyze social media posts, customer reviews, or any text-based content, this API streamlines the process and provides valuable sentiment insights.