0 / 0
Emotion classification

Emotion classification

The Emotion model in the Watson Natural Language Processing classification workflow classifies the emotion in the input text.

Workflow name

  • emotion_aggregated-workflow_en_stock
  • emotion_aggregated-workflow_fr_stock

Supported languages

  • English and French

Capabilities

The Emotion classification model is a pre-trained document classification model for the task of classifying the emotion in the input document. The model identifies the emotion of a document, and classifies it as:

  • Anger
  • Disgust
  • Fear
  • Joy
  • Sadness

Unlike the Sentiment model, which classifies each individual sentence, the Emotion model classifies the entire input document. As such, the Emotion model works optimally when the input text to classify is no longer than 1000 characters. If you would like to classify texts longer than 1000 characters, split the text into sentences or paragraphs for example and apply the Emotion model on each sentence or paragraph.

A document may be classified into multiple categories or into no category.

Capabilities of emotion classification based on an example
Capabilities Example
Identifies the emotion of a document and classifies it "I'm so annoyed that this code won't run --> anger, sadness

Dependencies on other blocks

None

Code sample

import watson_nlp

# Load the Emotion workflow model for English
emotion_model = watson_nlp.load('emotion_aggregated-workflow_en_stock')

# Run the Tone model
emotion_result = emotion_model.run("I'm so annoyed that this code won't run")
print(emotion_result)

Output of the code sample:

{
  "emotion_predictions": [
    {
      "emotion": {
        "anger": 0.6145385088342609,
        "disgust": 0.016446104781194168,
        "fear": 0.09267639538103885,
        "joy": 0.002527286676040879,
        "sadness": 0.19656945832751013
      },
      "target": "",
      "emotion_mentions": [
        {
          "span": {
            "begin": 0,
            "end": 39,
            "text": "I'm so annoyed that this code won't run"
          },
          "emotion": {
            "anger": 0.6145385088342609,
            "disgust": 0.016446104781194168,
            "fear": 0.09267639538103885,
            "joy": 0.002527286676040879,
            "sadness": 0.19656945832751013
          }
        }
      ]
    }
  ],
  "producer_id": {
    "name": "Ensemble Aggregated Emotion Workflow",
    "version": "0.0.1"
  }
}

Parent topic: Watson Natural Language Processing task catalog

Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more