Prediction for Sentiment

Returns a sentiment prediction for the given string.

Request Parameters

Name

Type

Description

Available Version

document

string

Text for which you want to return a sentiment prediction.

2.0

modelId

string

ID of the model that makes the prediction. The model must have been created from a dataset with a type of text-sentiment.

2.0

numResults

int

Number of probabilities to return. Optional. If passed, must be a number greater than zero.

The response is sorted by probability in descending order. For example, if you pass in 3, only the top three label and probability values are returned.

2.0

sampleId

string

String that you can pass in to tag the prediction. Optional. Can be any value, and is returned in the response.

2.0

Keep the following points in mind when sending text in for prediction:

  • If you omit the numResults parameter, the response returns probabilities for all the labels in the model.

Response Body

Name

Type

Description

Available Version

probabilities

array

Array of probabilities for the prediction.

2.0

sampleId

string

Value passed in when the prediction call was made. Returned only if the parameter is provided.

2.0

Probabilities Response Body

Name

Type

Description

Available Version

label

string

Probability label for the input.

2.0

probability

float

Probability value for the input. Values are between 0–1.

2.0

Passing Parameters as JSON

As an alternative to passing the modelId and document parameters as multipart/form-data fields, you can pass those parameters as JSON. You can pass the JSON directly as a string or reference a file that contains the JSON.

This cURL call sends a JSON string into the prebuilt sentiment model for classification. The Content-Type has changed to application/json.

curl -X POST -H "Authorization: Bearer <TOKEN>" -H "Cache-Control: no-cache" -H "Content-Type: application/json" -d "{\"modelId\":\"CommunitySentiment\",\"document\":\"The presentation was great and I learned a lot\"}" https://api.einstein.ai/v2/language/sentiment

Here's what the response might look like.

{
    "probabilities": [
        {
            "label": "positive",
            "probability": 0.8673582
        },
        {
            "label": "negative",
            "probability": 0.1316828
        },
        {
            "label": "neutral",
            "probability": 0.0009590242
        }
    ],
    "object": "predictresponse"
}

You can store the JSON in a file and reference that file. For example, the file sentiment.json might look like the following.

{
"modelId":"CommunitySentiment",
"document":"The presentation was great and I learned a lot"
}

This cURL call references that file.

curl -X POST -H "Authorization: Bearer <TOKEN>" -H "Cache-Control: no-cache" -H "Content-Type: application/json" -d @c:\data\sentiment.json https://api.einstein.ai/v2/language/sentiment

Rate Limit Headers

Any time you make an API call to the /sentiment resource, your rate limit information is returned in the header. The rate limit headers specify your prediction usage for the current calendar month only.

X-RateLimit-Limit 2000
X-RateLimit-Remaining 1997
X-RateLimit-Reset 2017-04-01 19:31:42.0

Header

Description

Example

X-RateLimit-Limit

Maximum number of prediction calls available for the current plan month.

2000

X-RateLimit-Remaining

Total number of prediction calls you have left for the current plan month.

1997

X-RateLimit-Reset

Date on which your predictions are next provisioned. Always the first of the month.

2017-04-01 22:07:40.0

Language