Comprehend.Client.
detect_sentiment
(**kwargs)¶Inspects text and returns an inference of the prevailing sentiment ( POSITIVE
, NEUTRAL
, MIXED
, or NEGATIVE
).
See also: AWS API Documentation
Request Syntax
response = client.detect_sentiment(
Text='string',
LanguageCode='en'|'es'|'fr'|'de'|'it'|'pt'|'ar'|'hi'|'ja'|'ko'|'zh'|'zh-TW'
)
[REQUIRED]
A UTF-8 text string. The maximum string size is 5 KB.
Note
Amazon Comprehend performs real-time sentiment analysis on the first 500 characters of the input text and ignores any additional text in the input.
[REQUIRED]
The language of the input documents. You can specify any of the primary languages supported by Amazon Comprehend. All documents must be in the same language.
dict
Response Syntax
{
'Sentiment': 'POSITIVE'|'NEGATIVE'|'NEUTRAL'|'MIXED',
'SentimentScore': {
'Positive': ...,
'Negative': ...,
'Neutral': ...,
'Mixed': ...
}
}
Response Structure
(dict) --
Sentiment (string) --
The inferred sentiment that Amazon Comprehend has the highest level of confidence in.
SentimentScore (dict) --
An object that lists the sentiments, and their corresponding confidence levels.
Positive (float) --
The level of confidence that Amazon Comprehend has in the accuracy of its detection of the POSITIVE
sentiment.
Negative (float) --
The level of confidence that Amazon Comprehend has in the accuracy of its detection of the NEGATIVE
sentiment.
Neutral (float) --
The level of confidence that Amazon Comprehend has in the accuracy of its detection of the NEUTRAL
sentiment.
Mixed (float) --
The level of confidence that Amazon Comprehend has in the accuracy of its detection of the MIXED
sentiment.
Exceptions
Comprehend.Client.exceptions.InvalidRequestException
Comprehend.Client.exceptions.TextSizeLimitExceededException
Comprehend.Client.exceptions.UnsupportedLanguageException
Comprehend.Client.exceptions.InternalServerException