Sentiment Analysis
Sentiment Analysis recognizes sentiment throughout the inputed text.
sentiment
boolean Default: false
Try this feature out in our API Playground!
Sentiment Analysis accepts an input text, divides it into a list of segments comprised of sections of the text, and identifies the sentiment of each segment. It also assigns an average sentiment to the entire text.
A sentiment
of positive
, negative
, or neutral
along with a sentiment_score
is identified for each segment of the source text, and an average
of the entire text’s sentiment is also provided along with the average sentiment_score
.
The break point for a sentiment_score
becoming positive or negative is +-0.333333333...
.
Enable Feature
To enable Sentiment, use the following parameter in the query string when you call Deepgram’s /read
endpoint:
sentiment=true
Basic Text Request
To analyze text from a file on your computer, run the following curl command in a terminal or your favorite API client.
Replace YOUR_DEEPGRAM_API_KEY
with your Deepgram API Key.
Basic URL Request
To analyze text from a hosted file, run the following curl command in a terminal or your favorite API client. (Try testing it out with the hosted file https://static.deepgram.com/examples/aura.txt.)
Read our Text Intelligence Getting Started guide, which will walk you through making a basic text request and a basic URL request with the Deepgram SDKs.
Query Parameters
Analyze Response
When the file is finished processing, you’ll receive a JSON response that has the following basic structure:
Use the API reference or the API Playground to view the detailed response.
The sentiment
values added to objects are:
sentiment
: The sentiment of the associated text (positive
|negative
|neutral
).sentiment_score
: A floating point value between -1 and 1 representing the sentiment of the associated span of text, with -1 being the most negative sentiment, and 1 being the most positive sentiment.
Response Properties
API Error Responses
Unsupported Language
Status 400
If you request Sentiment Analysis with an unsupported language by specifying a language code such as sentiment=true&language=es
or sentiment=true&detect_language=true
where the detected language is unsupported, you will get the error message below.
Token Limit Exceeded
Status 400
If the request’s input length exceeded the 150k token rate limit per request, you will get the error message below.
Missing Query Parameter
Status 400
If the request sent contained only the feature parameter (sentiment
) but not the language
parameter, you will receive this error.