Emotion

POST https://apiv2.indico.io/emotion
Predicts the emotion expressed by an author in a sample of text.

Current Version: 1

Private cloud endpoint

POST https://[cloud].indico.domains/emotion/[batch]/

Arguments

data – String | List – required – text to be analyzed
[v or version] – Integer – optional (defaults to 1) – specify model version
[top_n] – Integer – optional (defaults to 3) – only return this many of the most likely topics
[threshold] – Float – optional (defaults to .0) – only return topics with likelihood greater than this number

For an example of how to pass keyword arguments to the indico API in a post request, see the example below.

Output

This function returns a dictionary that maps from 5 emotions (anger, fear, joy, sadness, surprise) to the probability that the author is expressing the respective emotion.

# single output
{
    'anger': 0.007581704296171665,
    'joy': 0.07016665488481522,
    'fear': 0.8000516295433044,
    'sadness': 0.02512381225824356,
    'surprise': 0.06534374748375202
}

# batch output
[
    {
        'anger': 0.007581704296171665,
        'joy': 0.07016665488481522,
        'fear': 0.8000516295433044,
        'sadness': 0.02512381225824356,
        'surprise': 0.06534374748375202
    },
    {
        'anger': 0.0886223167181015,
        'joy': 0.10006538033485413,
        'fear': 0.1751064658164978,
        'sadness': 0.5425705313682556,
        'surprise': 0.09363535046577454
    }
]

Example

// Single Example
fetch('https://apiv2.indico.io/emotion', {
  method: 'POST',
  body: JSON.stringify({
    api_key: 'YOUR_API_KEY',
    data: 'I did it. I got into Grad School. Not just any program, but a GREAT program. :-)',
    threshold: 0.1
  })
})
  .then(r => r.json())
  .then(response => {
    console.log(response);
  })
  .catch(err => console.log(err));

// Batch Example
fetch('https://apiv2.indico.io/emotion/batch', {
  method: 'POST',
  body: JSON.stringify({
    api_key: 'YOUR_API_KEY',
    data: ['I did it. I got into Grad School. Not just any program, but a GREAT program. :-)', 'Like seriously my life is bleak, I have been unemployed for almost a year.'],
    threshold: 0.1
  })
})
  .then(r => r.json())
  .then(response => {
    console.log(response);
  })
  .catch(err => console.log(err));