ibm-watsonwatson-nlu

IBM Watson NLU Bluemix API not working for entities.sentiment=true


I'm using the Watson NLU service to get sentiment by entities and keywords, but the output has only document sentiment.

I don't know what's going wrong. I want to know the count of occurrences and the sentiment for keywords and entities.

Example output:

{
  "sentiment": {
    "document": {
      "score": 0.567576,
      "label": "positive"
    }
  },
  "language": "pt",
  "keywords": [
    {
      "text": "CNN teste",
      "relevance": 0.996733
    }
  ],
  "entities": [
    {
      "type": "Company",
      "text": "CNN",
      "relevance": 0.846667,
      "count": 3
    }
  ],
  "language": "pt"
}

Solution

  • I don't think there is an issue here as the sentiment results are dependent on the text you're sending to the API. I made this request using Postman with new credentials in Bluemix for the NLU service. I received sentiment for the entities, but not the keyword.

    However, if you make the request using some longer sample text as shown in the documentation (https://www.ibm.com/watson/developercloud/natural-language-understanding/api/v1/#post-analyze), the returned keywords do get a sentiment score.

    Also, if you add some additional text to the paramater you're sending in your question, you do get sentiment for the keywords. In this case I passed:

    {"text":"CNN test, CNN test, ola tudo bem? This is another CNN test for IBM Watson"}
    

    and received the following response:

    {
      "sentiment": {
        "document": {
          "score": 0,
          "label": "neutral"
        }
      },
      "keywords": [
        {
          "text": "ola tudo bem",
          "sentiment": {
            "score": 0.35067
          },
          "relevance": 0.942955
        },
        {
          "text": "CNN test",
          "sentiment": {
            "score": 0
          },
          "relevance": 0.778042
        },
        {
          "text": "IBM Watson",
          "sentiment": {
            "score": 0
          },
          "relevance": 0.370733
        }
      ],
      "entities": [
        {
          "type": "Company",
          "text": "CNN",
          "sentiment": {
            "score": 0
          },
          "relevance": 0.932122,
          "disambiguation": {
            "subtype": [
              "Broadcast",
              "AwardWinner",
              "RadioNetwork",
              "TVNetwork"
            ],
            "name": "CNN",
            "dbpedia_resource": "http://dbpedia.org/resource/CNN"
          },
          "count": 3
        },
        {
          "type": "Company",
          "text": "IBM Watson",
          "sentiment": {
            "score": 0
          },
          "relevance": 0.302698,
          "count": 1
        }
      ],
      "language": "en"
    }
    

    You can see from the above response that the keywords and entities are now returning a sentiment score.

    I suggest trying another test of the API with a more realistic (re: longer) text parameter and confirm the results.