Summarize this article with:
- Entity Sentiment Analysis combines Named Entity Recognition with sentiment analysis to determine the sentiment (positive, negative, or neutral) associated with specific entities in text.
- Developers can Do Entity Sentiment Analysis Using Python using a REST API that accepts standard inputs and returns structured JSON responses.
- Eden AI's Entity Sentiment Analysis API makes it easy to analyze how text feels about specific entities.
- Developers can Do Entity Sentiment Analysis Using Python using a REST API that accepts standard inputs and returns structured JSON responses.
- The integration works with Python, JavaScript, PHP, and any HTTP-capable language with minimal setup.
In this tutorial, you will learn how to use the Entity Sentiment Analysis API in 5 minutes using Python. Eden AI provides an easy and developer-friendly API that allows you to analyze sentiment at the entity level in text.
What is Entity Sentiment Analysis?
Entity Sentiment Analysis combines Named Entity Recognition with sentiment analysis to determine the sentiment (positive, negative, or neutral) associated with specific entities in text.
Getting Started
1. Sign Up: Create a free account here.
How to Implement Entity Sentiment Analysis using Python
Entity sentiment analysis now runs through an LLM: the script below sends the text to Eden AI’s OpenAI-compatible endpoint, https://api.edenai.run/v3/chat/completions, and asks for JSON that lists each entity with its sentiment.
import json
import requests
headers = {"Authorization": "Bearer <your_api_key>"}
url = "https://api.edenai.run/v3/chat/completions"
json_payload = {
"model": "openai/gpt-4o-mini",
"messages": [
{"role": "system", "content": "Extract the named entities from the text and give the sentiment expressed towards each one."},
{"role": "user", "content": "Apple is doing great, but Microsoft had issues."},
],
# Ask for JSON that follows this schema
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "entity_sentiment",
"strict": True,
"schema": {
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"text": {"type": "string"},
"sentiment": {"type": "string", "enum": ["positive", "negative", "neutral"]},
},
"required": ["text", "sentiment"],
"additionalProperties": False,
},
}
},
"required": ["items"],
"additionalProperties": False,
},
},
},
}
response = requests.post(url, json=json_payload, headers=headers)
print(json.loads(response.json()["choices"][0]["message"]["content"]))
Conclusion
Eden AI's Entity Sentiment Analysis API makes it easy to analyze how text feels about specific entities. Sign up free and start today!
.jpeg)
.jpg)