2

When I am sending text using Watson api NLU with my city which is located in India. I am getting empty entity. It should be come with data entity location. So how can i solve this problem in watson NLU.

The sentence being sent is:

mba college in bhubaneswar

where Bhubaneswar is the city

Simon O'Doherty
  • 9,259
  • 3
  • 26
  • 54
Yogesh Karodiya
  • 225
  • 5
  • 15

2 Answers2

4

So based on your comment sentence of:

"mba college in bhubaneswar"

Putting that into NLU and entity detection fails with:

Error: unsupported text language: unknown, Code: 400

The first issue is that because no language is specified, it tries to guess the language. But there is not enough there to guess (even if it is obvious to you).

The second issue is, even if you specify the language it will not fully recognise. This is because it's not a real sentence, it's a fragment.

NLU doesn't just do a keyword lookup, It tries to understand the parts of speech (POS) and from that, determine what the word means.

So if I give it a real sentence it will work. For example:

I go to an MBA college in Bhubaneswar

I used this sample code:

import json
from watson_developer_cloud import NaturalLanguageUnderstandingV1
from watson_developer_cloud.natural_language_understanding_v1 import Features, EntitiesOptions, RelationsOptions

ctx = {
  "url": "https://gateway.watsonplatform.net/natural-language-understanding/api",
  "username": "USERNAME",
  "password": "PASSWORD"
}
version = '2017-02-27'

text = "I go to an MBA college in Bhubaneswar"
#text = "mba college in bhubaneswar"

nlu = NaturalLanguageUnderstandingV1(version=version, username=ctx.get('username'),password=ctx.get('password'))
entities = EntitiesOptions()
relations = RelationsOptions()

response = nlu.analyze(text=text, features=Features(entities=entities,relations=relations),language='en')

print(json.dumps(response, indent=2))

That gives me the following results.

{
  "usage": {
    "text_units": 1,
    "text_characters": 37,
    "features": 2
  },
  "relations": [
    {
      "type": "basedIn",
      "sentence": "I go to an MBA college in Bhubaneswar",
      "score": 0.669215,
      "arguments": [
        {
          "text": "college",
          "location": [
            15,
            22
          ],
          "entities": [
            {
              "type": "Organization",
              "text": "college"
            }
          ]
        },
        {
          "text": "Bhubaneswar",
          "location": [
            26,
            37
          ],
          "entities": [
            {
              "type": "GeopoliticalEntity",
              "text": "Bhubaneswar"
            }
          ]
        }
      ]
    }
  ],
  "language": "en",
  "entities": [
    {
      "type": "Location",
      "text": "Bhubaneswar",
      "relevance": 0.33,
      "disambiguation": {
        "subtype": [
          "IndianCity",
          "City"
        ],
        "name": "Bhubaneswar",
        "dbpedia_resource": "http://dbpedia.org/resource/Bhubaneswar"
      },
      "count": 1
    }
  ]
}

If it's a case you are only going to get fragments to scan, then @ReeceMed solution will resolve it for you.

Simon O'Doherty
  • 9,259
  • 3
  • 26
  • 54
  • thanks for your great answer but I am implementing chatbot using NLU api so we can't be sure of user input. So I need solution that will work for all combination. – Yogesh Karodiya Dec 13 '17 at 12:41
  • The code above is just using the WDC SDK. It's going to be the same as the API. I recommend to get representative end user input, so as to not waste time on something that may not be needed, or an easier solution may be possible. – Simon O'Doherty Dec 13 '17 at 13:42
1

Screenshot of NLU Service responseIf the NLU service does not recognise the city you have entered you can create a custom model using Watson Knowledge Studio which can then be deployed to the NLU Service, giving customised entities and relationships.

ReeceMed
  • 93
  • 7
  • thanks for your response but I think this is basic feature and it should be include in NLU. Although when I enter full detail text or any url which contain data related to my city then its working fine but its not working with short sentences. – Yogesh Karodiya Dec 13 '17 at 10:09
  • what is the city name you are trying to recognise? NLU had depth in its capability and so it does seem strange – ReeceMed Dec 13 '17 at 10:12
  • check this sentance into NLU "mba college in bhubaneswar" here bhubaneswar is city – Yogesh Karodiya Dec 13 '17 at 10:17