IBM Watson Natural Language Understanding (NLU) offers a powerful tool for emotion analysis, enabling users to detect specific emotions from text data, such as joy, anger, sadness, fear, or disgust. Here is a stepwise illustration of how the Watson NLU service can be used to perform emotion analysis:
By using Watson NLU for emotion analysis, businesses and researchers can automate the understanding of human emotions, allowing them to make data-driven decisions and respond more effectively to customer needs and market trends.
import requests
import json
from requests.auth import HTTPBasicAuth
# Watson NLU API details
api_key = 'YOUR_API_KEY'
url = 'https://api.eu-gb.natural-language-understanding.watson.cloud.ibm.com/instances/e1560be7-a6db-4e1c-aea5-82898f2487be/v1/analyze?version=2021-08-01'
# Text to be analysed
text = '''
iphone 16 is truly amazing! I’ve never been happier with a purchase.
But the delivery was very late, and that was disappointing.
'''
# Specify the features to be analysed - in this case, emotion
data = {
"text": text,
"features": {
"emotion": {}
}
}
# Make the API request with Basic Authentication
response = requests.post(url, auth=HTTPBasicAuth('apikey', api_key), json=data)
# Parse the response
emotion_data = response.json()
print(json.dumps(emotion_data, indent=2))
{ "usage": { "text_units": 1, "text_characters": 131, "features": 1 }, "language": "en", "emotion": { "document": { "emotion": { "sadness": 0.307645, "joy": 0.66182, "fear": 0.033113, "disgust": 0.02233, "anger": 0.022124 } } } }
Use the Search Bar to find content on MarketingMind.
Contact | Privacy Statement | Disclaimer: Opinions and views expressed on www.ashokcharan.com are the author’s personal views, and do not represent the official views of the National University of Singapore (NUS) or the NUS Business School | © Copyright 2013-2025 www.ashokcharan.com. All Rights Reserved.