Sentiment Analysis
The sentiment endpoint checks the sentiment for a given text - positive, negative, or neutral. The overall sentiment is returned as well as the sentiment for each sentence for a more fine-grained breakdown.
If you're looking for specific emotions/tones, please see our tone endpoint.
Sample Code
- cURL
- JavaScript
- Python
curl -X POST https://api.sapling.ai/api/v1/sentiment \
-H "Content-Type: application/json" \
-d '{"key":"<api-key>", "text":"Im really stoked about this! This was a very difficult project. Excited to see it go through!"}'
import axios from 'axios';
async function run(text) {
try {
const response = await axios.post(
'https://api.sapling.ai/api/v1/sentiment',
{
key: '<api-key>',
text,
},
);
const {status, data} = response;
console.log({status});
console.log(JSON.stringify(data, null, 4));
} catch (err) {
const { msg } = err.response.data;
console.log({err: msg});
}
}
run("I'm really stoked about this! This was a very difficult project. Excited to see it go through!");
import requests
from pprint import pprint
response = requests.post(
"https://api.sapling.ai/api/v1/sentiment",
json={
"key": "<api-key>",
"text": "I'm really stoked about this! This was a very difficult project. Excited to see it go through!"
}
)
pprint(response.json())
Sample Response
{
"overall": [
[ 0.9966725875565317, "POSITIVE" ]
],
"results": [
[
[ 0.9962439247756265, "POSITIVE" ]
],
[
[ 0.8007598668336868, "NEGATIVE" ],
[ 0.04219657927751541, "POSITIVE" ]
],
[
[ 0.9941994925029576, "POSITIVE" ],
[ 0.0009521204046905041, "NEUTRAL" ]
]
],
"sents": [
"I'm really stoked about this!",
"This was a very difficult project.",
"Excited to see it go through!"
]
}
Request Parameters
POST to https://api.sapling.ai/api/v1/sentiment
key: String
32-character API key.
text: String
Text to analyze the sentiment for.
Response Parameters
The sentiment endpoint contains three fields:
sents
: The sentences the text contains.overall
: A list of tuples of the form(probability, sentiment)
.results
: For each sentence, a list item containing a list of tuples of the form(probability, sentiment)
.