question

Shimmur-9947 avatar image
0 Votes"
Shimmur-9947 asked romungi-MSFT commented

How to get overall sentiment score using Text Analytics API?

I'm making a post request to the Text Analytics API to run sentiment analysis on a sample text and am successfully getting back the following response. Going by this response, I don't see a means to grab a single overall score for the document - just the individual positive, negative, or neutral scores. How do I get the overall score as I've seen in sample docs online?
Do I need to use the client library instead? Appreciate any help.
{
"documents":
[
{"id":"1",
"sentiment":"negative",
"confidenceScores”: {“positive":0.0,"neutral":0.0,"negative":1.0},
"sentences”: [
{“sentiment":"negative",
"confidenceScores":
{"positive":0.0,"neutral":0.0,"negative":1.0},
"offset":0,
"length":27,
"text": "['it is noisy outside']"
}
],
"warnings":[]}],
"errors":[],
"modelVersion":"2020-04-01"}



azure-cognitive-servicesazure-text-analytics
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

romungi-MSFT avatar image
0 Votes"
romungi-MSFT answered romungi-MSFT commented

@Shimmur-9947 Could you post the request body and the API used in your request? I have tried the sentiment API and it provides the response with the expected results. For example:

 API: https://<myresource>.cognitiveservices.azure.com/text/analytics/v2.1/sentiment

Body:

 {
   "documents": [
     {
       "id": "1",
       "text": "If this demo doesn't work I will be super sad",
       "language": "en"
     },
     {
       "id": "2",
       "text": "Español es muy difícil de aprender",
       "language": "es"
     },
     {
       "id": "3",
       "text": "I really really love machine learning",
       "language": "en"
     },
     {
       "id": "4",
       "text": "Le soleil se lève à l'Est",
       "language": "fr"
     }
   ]
 }

Response:

 {"documents":[{"id":"1","score":0.0073043704032897949},{"id":"3","score":0.94009941816329956},{"id":"2","score":0.44219660758972168},{"id":"4","score":0.53425812721252441}],"errors":[]}
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Shimmur-9947 Did the above response help to check if the response is returned as required for your application?

0 Votes 0 ·